Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
frasten
Beginner


Joined: 06 Jan 2006
Posts: 24

PostPosted: 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").
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: 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."
Reply with quote
frasten
Beginner


Joined: 06 Jan 2006
Posts: 24

PostPosted: 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!
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: 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."
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Jan 03, 2008 9:26 am   
 
True. Suck on that, #NOOP - hopefully I got them all.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
frasten
Beginner


Joined: 06 Jan 2006
Posts: 24

PostPosted: 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 Smile
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net