|
zmudnoob Beginner
Joined: 09 Sep 2005 Posts: 14
|
Posted: Tue Sep 13, 2005 8:50 pm
easy scripting help |
I'm using zmud 7.13b in windows xp and trying to create an alias that will take each item from one variable (@stringlist) and put it into another variable (@new) but with each item numbered and on it's own line. I can easily put each on it's own line with %expandlist(@stringlist,%cr) so the old variable (@stringlist) contains:
a bag of tricks|small ice cream cone|purple earring
and the new variable (@new) looks like:
a bag of tricks
small ice cream cone
purple earring
what I want is the new variable (@new) to actually look like:
1:a bag of tricks
2:small ice cream cone
3:purple earring
It seems like this should be easy to do but I just can't get my head around it because I'm fairly new to scripting. Any help would be greatly appreciated. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Sep 13, 2005 9:05 pm |
#alias enumerate {#loop 1,%numitems(@%1) {#variable %2 %replaceitem(%concat(%i,":",%item(%1,%i)),%i,%1)}}
%1 -- old list
%2 -- new list
enumerate old new |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
zmudnoob Beginner
Joined: 09 Sep 2005 Posts: 14
|
Posted: Tue Sep 13, 2005 9:58 pm |
Thanks for the quick response! The alias created a new variable with the value of
3:
(because I had 3 items in the old variable) and none of the items themselves made it over to the new variable from the old. Any ideas why? |
|
|
|
Vitae Enchanter
Joined: 17 Jun 2005 Posts: 673 Location: New York
|
Posted: Wed Sep 14, 2005 12:53 am |
This works for me if ya dont mind having another variable
#alias enumerate {
#LOOP %numitems( @new) {#ADDITEM new2 {%i: %item( @new, %i)}}
#VARIABLE new @new2
#VARIABLE new2 {} {}
} |
|
|
|
alluran Adept
Joined: 14 Sep 2005 Posts: 223 Location: Sydney, Australia
|
Posted: Wed Sep 14, 2005 11:07 am |
#alias enumerate {
#LOOP %numitems( @new) {#var new %replaceitem("1: "%item(@new,%i)%char(10)%char(13),%i,@new)}
}
that should do it with no new variables needed |
|
_________________ The Drake Forestseer |
|
|
|
zmudnoob Beginner
Joined: 09 Sep 2005 Posts: 14
|
Posted: Wed Sep 14, 2005 1:05 pm |
Yay! Got it working very nicely :-) Thank you all for your help.
|
|
|
|
|
|