|
jat63 Wanderer
Joined: 22 Sep 2003 Posts: 53 Location: United Kingdom
|
Posted: Thu Jun 21, 2007 3:51 pm
[1.33] Problems with #ADDKEY and local variables - Solved |
I thought from the release notes that V1.28 fixed problems with #ADDKEY and local variables. I still seem to be having problems with them. For example, the following code:
Code: |
db1=""
tdb=db1
$tdb=db1
#addkey db1 test1 123
#addkey @tdb test2 124
#addkey $tdb test3 125 |
Tries to add three entries to the db1 database variable. After the code has been run I expected to see three entries but only have the first two. Should this have worked?
Maybe I have answered this for myself - is using the #addkey $local form of the command used to create a database variable in a local variable? If so is there a syntax I can use to use #addkey when the name of the db is in a local variable (as was the original intent with
the original code?
Code: |
#addkey $tdb test3 125 |
|
|
Last edited by jat63 on Thu Jun 21, 2007 5:43 pm; edited 1 time in total |
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Thu Jun 21, 2007 5:29 pm |
It may be a hack, but you could always:
Code: |
#EXEC %concat("#ADDKEY ", $tdb, " test3 125")
|
The concat would create the line "#ADDKEY db1 test3 125" and then the #EXEC would execute it.
There may be an expansion character ([],<>,(),or something) that will do the same without concat and exec, but that would work. |
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jun 21, 2007 5:35 pm |
I believe the change to #addkey in this situation was deliberate - you're actually performing the #addkey on the local variable itself in your example, which may or may not be what you intended. Before 1.28, there was no way to make a local variable have keys. Another way to get the result you're after is:
#addkey %eval($test) test3 125 |
|
|
|
jat63 Wanderer
Joined: 22 Sep 2003 Posts: 53 Location: United Kingdom
|
Posted: Thu Jun 21, 2007 5:42 pm |
Thank you both - problem now solved
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Jun 21, 2007 6:40 pm |
I believe it works as designed. For you last command you are not explicitly expanding $tdb so what CMUD is doing is redefining the local variable to be a DB variable with one entry.
If you did a #SHOWDB $tdb you would see the third item. Consider this code.
Code: |
db1=""
tdb=db1
$tdb=@db1
#addkey db1 test1 123
#addkey @tdb test2 124
$tdb=@db1
#addkey $tdb test3 125
#showdb @db1
#showdb $tdb |
When you show $tdb now it displays all three.
Alternatively you can force the the expansion of the local variable like so.
Code: |
#addkey %eval($tdb) test3 125 |
Hoep that helps. |
|
_________________ Asati di tempari! |
|
|
|
|
|