help with finding if variable is set

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

dok
a ghoul
a ghoul
Posts: 127
Joined: Mon Mar 15, 2004 3:38 pm

help with finding if variable is set

Post by dok » Fri Apr 09, 2004 2:04 am

Which way would be the best and most reliable to find out of a variable is/isn't empty that would also work in arrays and with String.Arg?

This is something I've come up with for strings using String.Arg, but is there an easier or better way?

Code: Select all

/declare string global
/varset string "This is a string"

/newif ${Bool[${String[@string].Arg[3]}]} {
    /echo true
} else /echo false

/newif ${Bool[${String[@string].Arg[6]}]} {
    /echo true
} else /echo false
Leaving off the $Bool part crashes the if when the value is found


I really dont know what to do about going through an array. this is what I have so far, but its never returning false.

Code: Select all

/declare array1 array
/declare array_count global
/varset array1(0) test
/varset array1(1) test
/varset array1(2) test

/varset array_count 0
:checkarray
    /newif ${Bool[@array1(@array_count)]} {
        /echo @array_count - true  - @array1(@array_count)
    } else {
        /echo @array_count - false - @array1(@array_count)
        /return
    }
    /varadd array_count 1
    /goto :checkarray
Also tried w/o the Bool, but it never seems to return falso because when its unset, it returns "UNDEFINED-ARRAY-ELEMENT", so I tried this...

/newif ${String[@array1(@array_count)].NotEqual["UNDEFINED-ARRAY-ELEMENT"]}

as my if statement, and it works, but is there a better way?


(btw, using 4/8/04 build with mq2parms and mq2data enabled)

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Fri Apr 09, 2004 7:09 am

As far as I know:

Code: Select all

/newif ${String[@array1(@array_count)].NotEqual[UNDEFINED-ARRAY-ELEMENT]} /echo Whatever
Is the best way.