Simpler inventory for random names

I was trying to use the inventory systems created by other users to deal with direct links for randomized item names, but I couldn’t figure out how to do it, and I ended up bumping into a solution that does what I need with a simpler code (I think), using widget to create links. This example is from a game I’m working on. It creates machines populated by random snacks with names created from a combination of 3 lists. You can click on the item name to either buy from the machine (adding to the bag) or eat a snack on your bag. Also it tests the variable. Here’s the code:

Passage
<<set $prep to ["baked","dried"]>>\
<<set $flavor to ["apple","banana","potato"]>>\
<<set $form to ["chips","roll"]>>\
<<set $favsnack to $prep.random() + " " + $flavor.random() + " " + $form.random()>>\
<<set $machine to []>><<set $bag to []>>\
<<="Your favorite snack is "+$favsnack+".">>
<span id="op">\
	<<="Choose an option:">>
	<<link "Find a snack machine">>\
		<<set $machine to []>>\
		<<replace "#op2">>\
			<<="Choose a snack to buy:">>
			<<for _n to 0; _n lt 10; _n++>>\
				<<run $machine.push($prep.random() + " " + $flavor.random() + " " + $form.random())>>\
				<<link_buy _n $machine[_n]>>
			<</for>>\
		<</replace>>\
	<</link>>
	<<link "Eat a snack">>\
		<<if $bag.length gt 0>>\
			<<replace "#op2">>\
				<<="Choose a snack to eat:">>
				<<for _n to 0; _n lt $bag.length; _n++>>\
					<<link_eat _n $bag[_n]>>
				<</for>>\
			<</replace>>\
		<<else>>\
			<<replace "#op2">><<="You have no snacks.">><</replace>>\
		<</if>>\
	<</link>>
</span>
<span id="op2"></span>
Widget
<<widget "link_buy">>\
	<<link $args[1] >>\
		<<replace "#op2">><<= "You got the "+$args[1]+" from the machine.">><</replace>>\
		<<run $bag.push($machine[$args[0]])>>\
	<</link>>\
<</widget>>

<<widget "link_eat">>\
	<<link $args[1] >>\
		<<replace "#op2">><<= "You eat the "+$args[1]+" and feel better.">><</replace>>\
		<<if $args[1] is $favsnack>><<append "#op2">><<= " It is your favorite!">><</append>><</if>>\
		<<run $bag.deleteAt($args[0])>>\
	<</link>>\
<</widget>>

Let me know if this is useful in anyway. It is working for me. (Reminder: the widget code must be located in another passage with the special tag “widget”. It is similar to the StoryInit passage.)