/if (conditions) with strings

Chatwiththisname

Learning2Code
Joined
Sep 28, 2008
Messages
1,234
Reaction score
54
Points
48
Location
Texas
I'm trying to do some if conditions with strings. I run into a lot of issues with trying to check for things that are strings.

for example. /if (${Me.Class} == Berserker) /dothings

Problem is that I run into a non numeric B. This occurs at ${Me.Class} before it even runs into == Berserker.

Is there something I am missing or are strings not comparable? Logically speaking if one equals the other, shouldn't the result be true? Or does it not have string comparison built in? I mean I've gotten around that by using ID's instead, but figured there might be able to compare strings as there are other locations where ID's are harder to come by via additional variables and coding.

INI file setting PullCast=Flame Shock

then use PullCastID = ${Spell[${PullCast}].ID} then use /if (${PullCastID} != Null) /dothings

But yeah, question is can I compare strings. if so, how.
 
${Me.Class.Name.Equal[Berserker]}

Again, for that situation it applies. But it doesn't always apply.

If I create custom variables such as a pull skill that requires user input into the INI file and they type Flame Shock then I can't do a check for an INI value by saying

Code:
/if (${PullCast]} == NULL) {
    /ini "${Filename}" "Configuration" "PullCast" "NULL"
}

because it evaluates to (Flame Shock == Flame Shock) which are strings and thus I run into non-numeric.

When I try

Code:
/varset PullCast ${Ini[${Filename},Configuration,PullCast]}
/varset PullCastID ${Spell[${PullCast}].ID}

/if (${PullCastID]} == NULL) {
	/ini "${Filename}" "Configuration" "PullCast" "NULL"
}

it for some reason registers that PullCastID is NULL and resets the INI to Null, so the next time I run it, the PullCast field is null.
 
/varset PullCast ${Ini[${Filename},Configuration,PullCast,NULL]}

/if (${PullCast.Equal[NULL]})
 
/varset PullCast ${Ini[${Filename},Configuration,PullCast,NULL]}

/if (${PullCast.Equal[NULL]})

Thanks for that. I didn't realize that the .Equal was valid without an accessor method. I'm stuck on java and I've been trying to figure out how to work with this code without making my own constructor accessors and mutators. Suppose this helps things quite a bit.
 
Last edited:
/varset PullCast ${Ini[${Filename},Configuration,PullCast,NULL]}

/if (${PullCast.Equal[NULL]})

Thanks for that. I didn't realize that the .Equal was valid without an accessor method. I'm stuck on java and I've been trying to figure out how to work with this code without making my own constructor accessors and mutators. Suppose this helps things quite a bit.

Easiest way to think about it is all variables in MQ2 Macros are really just strings. There are no real types in MQ2 besides that. You can use .Equal on pretty much any variable or method, even if it returns a number.

There is also .NotEqual which works the same ${Variable.NotEqual[Value]}. While !${Variable.Equal[Value]} would work, you are forcing a double evaluation that way so .NotEqual would be ever so slightly quicker.