|
missinglink Beginner
Joined: 09 Feb 2010 Posts: 15
|
Posted: 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 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
missinglink Beginner
Joined: 09 Feb 2010 Posts: 15
|
Posted: 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 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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".
|
|
|
|
missinglink Beginner
Joined: 09 Feb 2010 Posts: 15
|
Posted: 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 |
|
|
|
|
|