Passing a String Through $item[]?

Sponge

New member
This has been bugging me for a while now, so I'm hoping someone around here may be able to set me straight. I'm writing a script that is basically a consumption script. I've made several before, but my laziness doesn't like having to make a new script every time I change my diet. As such, I designed this script to be highly customizable with very little effort required to completely rework the user's diet.

Long story short, I store the preferences (such as the types of food the user wants to eat) as strings, which presents a problem when I go to actually purchase that item.

The relevant code snippet looks a bit like this:
buy(foodn, $item[food]);
'foodn' is the number it's supposed to buy, and 'food' is the item. Mafia doesn't like this, and spits out 'Bad item value: "food".' Is there any way around this?

Thanks
 

Veracity

Developer
Staff member
buy(foodn, $item[food]);

$item[...] must be a constant at script parse time. To convert a string to an item at execution time, do:

buy(foodn, to_item(food) );
 
Top