|
frasten Beginner
Joined: 06 Jan 2006 Posts: 24
|
Posted: Wed Jan 02, 2008 9:35 pm
[2.18] Arrays and local variables |
Hi, I have a problem with this:
Code: |
#var myarray %array(%null)
; This will output 0
#echo Size of myarray: %arrhigh(myarray)
$myvar = "test"
#noop %arrset(myarray, %arrhigh(myarray),$myvar)
#showarr myarray
|
So, we have:
- myarray, an array variable
- myvar, a local variable containing "test"
What I expect is that the index 0 of myarray gets filled with "test".
But it is always empty.
Are there any bugs with it or am I doing something wrong?
Note: if I try to initialize myarray as:
Code: |
#var myarray %array() |
CMud crashes ("Error creating variant or safe array"). |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Wed Jan 02, 2008 11:24 pm |
if you change
Code: |
#noop %arrset(myarray, %arrhigh(myarray),$myvar) |
to
Code: |
#call %arrset(myarray, %arrhigh(myarray),$myvar) |
Everything works out. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
frasten Beginner
Joined: 06 Jan 2006 Posts: 24
|
Posted: Thu Jan 03, 2008 12:41 am |
Ok, it worked, thank you very much :-)
However, I think the help files should be updated, because they always contain examples with #noop.
And, too bad, arrays can not be used in local variables... I hope they will work in future! :-)
Bye! |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Thu Jan 03, 2008 3:36 am |
If you want to use local vars why not switch to stringlists.
I think the primary use for Arrays is supposed to be for making an arrays suitable for passing to COM objects.
And there are stringlist functions to match any of the array functions. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 03, 2008 4:15 am |
Dharkael's correct, arrays are only really for passing to COM objects - stringlists do everything arrays can and more.
If you spot any help files with an example with #noop, could you use the "post your comments" link at the bottom and tell us? It takes about a second to change it but much longer to troll through every help file trying to find them. Same goes for any other errors you spot. |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Thu Jan 03, 2008 9:15 am |
2 Fang Xianfu
You may search for NOOP within CMUD help. Btw, there are only several articles left with "#NOOP %function" in them. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 03, 2008 9:26 am |
True. Suck on that, #NOOP - hopefully I got them all.
|
|
|
|
frasten Beginner
Joined: 06 Jan 2006 Posts: 24
|
Posted: Thu Jan 03, 2008 11:29 am |
@Dharkael:
I didn't switch to string lists because I thought they were slower, using many records, but I will definitely give them a try.
@Fang Xianfu:
Thank you very much for your work |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 03, 2008 5:00 pm |
String lists are implemented using hash tables, same as arrays, in 2.x. There shouldn't be any noticeable difference now.
|
|
|
|
|
|