Senior moment with $item[]

fronobulax

Developer
Staff member
What is allowed in the brackets of $item[]?

PHP:
print($item[dry martini]);
print($item["dry martini"]);
string ss = "dry martini";
print($item[ss]);

The code fragment above fails with
Bad item value: "ss" (temp.ash, line 4)

which confuses me. I'm not really expecting different behavior between what seems to me to be a string constant and a string variable set to the same value as the constant. I'm getting a sense of deja vu about this but obviously the lesson didn't stick so please be patient with me.

Thanks.
 
All of the syntax forms starting with a $ are constants, evaluated at compile time, just like a string in double-quotes. Would you expect the value of the string "hello" to change just because you also had a variable named hello?

Run-time type conversions are done via functions like to_item().
 
Thank you. I keep wanting to make $item[] and friends into an array or a function. Maybe this time the fact that it is a constant will stick with me.
 
Back
Top