|
Cbisazza Wanderer
Joined: 27 Feb 2003 Posts: 69 Location: Australia
|
Posted: Sun Feb 26, 2006 12:28 am
expanding variable names |
When upgrading from 7.05 to 7.21 I noticed a problem with most of my scripts - This was traced to a particular syntax not working any more.
As an example, say I want to parse money in the format:
You have 2 gold and 1 silver Dollars
You have 1 silver Yen
One way I would do it (assuming multiple currencies):
#VAR Currencies {DOLLARS|...}
#TRIGGER {(%d) silver*({@Currencies})} {#ADD money.<%2> %1 }
The problem seems to be with the variable expansion 'money.<%2>'. This works fine in 7.05 (and before).
I've tried substituting the '.' with '_' - just in case Zmud was objecting to the list-like syntax, but that didn't help. The list/array-like references I was getting while debugging disappeared, but the variable still wasn't set.
Anyone have any ideas on what is happening - and on how I can get this to work again?
Thanks! |
|
_________________ Chris. |
|
|
|
Cbisazza Wanderer
Joined: 27 Feb 2003 Posts: 69 Location: Australia
|
Posted: Sun Feb 26, 2006 1:03 am |
OK, fixed it. Looks like the <> part is not required any more.
Seems to expand properly without them. |
|
_________________ Chris. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Feb 26, 2006 1:06 am |
These both should work.
#TRIGGER {(%d) silver*({@Currencies})} {#ADD money.%2 %1}
#TRIGGER {(%d) silver*({@Currencies})} {#ADD {money.%2} %1}
A much more verbose syntax would be:
#TRIGGER {(%d) silver*({@Currencies})} {#ADDKEY money {%2} {%eval(%db(@money,"%2")+%1)}}
I tend to use the verbose syntaxes for permanent scripts, because they are definitely going to be supported between all future versions of zMud, and generally are supported by much older versions as well. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Cbisazza Wanderer
Joined: 27 Feb 2003 Posts: 69 Location: Australia
|
Posted: Sun Feb 26, 2006 10:19 am |
Thanks for the note Vijilante!
I probably will convert database manipulations to the last format - half of them now explicitly use #ADDKEY, converted while trying to figure out how to solve the problem. didn't get to the %eval bit, however - that's a neat way of doing it.
Thanks very much! |
|
_________________ Chris. |
|
|
|
|
|