There a better way to do this?

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

Draimen
a lesser mummy
a lesser mummy
Posts: 69
Joined: Sun Jan 25, 2004 3:13 pm

There a better way to do this?

Post by Draimen » Sun Jun 20, 2004 3:46 am

/declare index int local

/declare var1 local
/declare var2 local
/declare var3 local

/varset var1 Name1
/varset var2 Name2
/varset var3 Name3

/for index 1 to 3 [1]
/echo ${var${index}}
/next index

Just an example of what I wanted to do. Basically have a set list of names or what not and return/output those names one by one in a loop.

That code works, just wondering if there was an easier way cause if you had a long list then it would suck having to declare and set all the vars.

s16z
a ghoul
a ghoul
Posts: 97
Joined: Thu Apr 01, 2004 12:03 pm

Post by s16z » Sun Jun 20, 2004 8:29 am

Code: Select all

/declare index int local
/declare MyArray[3] string local

/varset MyArray[1] Name1
/varset MyArray[2] Name2
/varset MyArray[3] Name3

/for index 1 to 3
    /echo ${MyArray[${index}]}
/next index
Declare reduced to 1 line, but there is no way around setting each one up, unless you want them all to be the same value, example:

Code: Select all

/declare MyArray[10] string local UNDEFINED-VALUE
This sets them all to the string "UNDEFINED-VALUE".

Draimen
a lesser mummy
a lesser mummy
Posts: 69
Joined: Sun Jan 25, 2004 3:13 pm

Post by Draimen » Sun Jun 20, 2004 3:46 pm

Sweet, thanks. Still learning here and was unsure how to use arrays hehe.