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
missinglink
Beginner


Joined: 09 Feb 2010
Posts: 15

PostPosted: Thu Feb 18, 2010 3:46 am   

zScript split function: comma delimited variable stored string into array
 
Hi all,

i'm trying to do the following whilst keeping it all in zscript (to keep the speed up).

I have a regexp which populates a variable as follows:

@list = enemy1:a,enemy2:~,enemy3:a,enemy4:b

i'd like to convert it into an array for processing, as follows:

@listAsArray(0) = enemy1:a
@listAsArray(1) = enemy2:~
etc.

Anyone know how to do this in zscript? trying to avoid using jscript or vbscript (although i'm not sure what the performance penalty would be, since it needs to do this every 2 seconds on a potentially large block of text).

Thanks for any help,

m-L
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Feb 18, 2010 5:31 am   
 
Use stringlists. Stringlists are separated via the pipe (|) symbol, and unlike datarecord variables they maintain their order. They are also saved in string format, so string-related functions such as %concat() can be used to put them together.

Commands and functions of interest:
#additem and %additem()
#delitem and %delitem()
#delnitem
%replaceitem()
%pop()
%push()
_________________
EDIT: I didn't like my old signature
Reply with quote
missinglink
Beginner


Joined: 09 Feb 2010
Posts: 15

PostPosted: Fri Feb 19, 2010 1:12 am   
 
Thanks Matt,

i think that will solve my problem!

Thanks for your help, much appreciated.

Cheers,

m-L
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Feb 19, 2010 2:30 pm   
 
I'm curious what the ":a", ":~", and ":b" signify. Are you really trying to store a string "enemy1:a", or are you trying to associate "enemy1" with "a"? If the latter, then a database variable is actually a better way to do it. With a database variable, you can retrieve the key "enemy1" from the variable and get the value "a".
Reply with quote
missinglink
Beginner


Joined: 09 Feb 2010
Posts: 15

PostPosted: Wed Feb 24, 2010 4:04 am   
 
Hi Rahab,

thanks for your interest.

Actually, that is the way the information is delivered from the mud (a list of creatures which are following me around) and the value e.g :a or :b or :~ refers to the health of the creature. they don't tend to last very long so basically i have a "status window" where i have them listed, and have them differentiated from the other things following me around.

I need them in an array because i need to do processing on them, e.g counts of certain types, etc.

Cheers,

m-L
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