Special type value--Veracity's tutorial

ThePowerTool

New member
"While the special-typed variables are declared the same as primitive types (ie: item i), special-typed static values are declared very differently from static values. To specify that a value is of a special type, $typename[value] must be used, with a string in square brackets designating the intended value (ie: $item[cog])."--Veracity's tutorial (Advanced.html).

I have a question regarding this and a sample script:

script "test-item-w-var.ash"

item test_i=$item[bottle of Pete's Sake];
print("test_i="+test_i);

string my_str="bottle of Pete's Sake";
# test_i=$item[my_str];
# print("test_i="+test_i);

Why does the 1st declaration work when simply uncommenting the 2nd declaration yields:
Bad item value: "my_str" (test-item-w-var.ash, line 7, char 14 to char 20)
 
$item[bottle of Pete's Sake] means the item named "bottle of Pete's Sake". $item[my_str] means the item named "my_str", but no such item exists. You can't use variable in the brackets like that. If you want to convert a string into an item, you have to use to_item(my_str) (or, equivalently, my_str.to_item() ).
 
"$typename[value] must be used, with a string in square brackets" is incorrect? There's no disambiguation? If I understand you, I think it should say "$typename[value] must be used, with a static value pointing to a <key expression>" (using Data Structures as a reference).

And does this also affect mall_prices()? The primary reason I created the OP was a desire to only enter static data once and use disambiguation for every subsequent reference. I tried using mall_prices(my_str) where my_str was a comma separated list. It works flawlessly with a static string but fails with errors when I use a string variable with the same comma-separated data.

Can I sneak around this limitation using a function e.g.:
function(string1,string2,string3,string4){}
and then call with
my_str="bottle of Pete's Sake, cog, spring,fortune cookie";
funtion(my_str);

Thank you for your help!
 
Back
Top