/if with non-numeric variables

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

Moderator: MacroQuest Developers

srenex
orc pawn
orc pawn
Posts: 10
Joined: Sun Dec 28, 2003 3:49 am

/if with non-numeric variables

Post by srenex » Sat Jun 12, 2004 2:04 am

I'm making a macro that will work with different cases based on the direction one is headed.


#turbo

Sub Main
/declare feettraveled int outer
/declare newy int outer
/varset feettraveled 50

/if (${Me.Heading} == N) {
${newy} = ${Math.Calc[${Me.Y} + ${feettraveled}]}

/echo ${newy}
}
/return


This all I've tried so far, and it's only for North. I intend for feettraveled to be inputted, but I'll worry about that later. My error is "error failed to parse /if condition '(N==N)', non-numberic encountered". Any help is appreciated, thanks in advance.

Falco72
a hill giant
a hill giant
Posts: 215
Joined: Fri Sep 26, 2003 3:24 am

Post by Falco72 » Sat Jun 12, 2004 2:20 am

Change

Code: Select all

/if (${Me.Heading} == N) {
to

Code: Select all

/if (${Me.Heading[color=red].Equal[N]}[/color]) {
I will suggest you to read the readme.chm in your MQ2 folder.
Heading give out a string and /if works only with numeric values. Equal will check to see if the string you put in the [] is equal (true and zero) or not (false and non zero value) with the Heading function. At the end the parse will read the line like

Code: Select all

/if (TRUE) {
.
.
.
} else {
.
.
.
}

srenex
orc pawn
orc pawn
Posts: 10
Joined: Sun Dec 28, 2003 3:49 am

Post by srenex » Sat Jun 12, 2004 3:07 am

That didn't work... the error I get is: No such 'heading' member 'Equal'
=( Thanks though. I'm understanding a little more though.

Falco72
a hill giant
a hill giant
Posts: 215
Joined: Fri Sep 26, 2003 3:24 am

Post by Falco72 » Sat Jun 12, 2004 3:13 am

Bah, I should read the manual too:

Code: Select all

Heading  
 Members  
 int Clock The nearest clock direction, e.g. 1-12 
 
float Degrees Heading in degrees (same as casting to float) 
 
float Degrees Heading in degrees Counter-Clockwise (the way the rest of MQ2 and EQ uses it, and is expected by older macros) 
 
string Name "south" "south by southeast" etc 
 
string ShortName "S" "SSE" etc 
 
To String Same as ShortName
Try:

Code: Select all

/if (${Me.Heading[color=red].ShortName[/color].Equal[N]})

Falco72
a hill giant
a hill giant
Posts: 215
Joined: Fri Sep 26, 2003 3:24 am

Post by Falco72 » Sat Jun 12, 2004 3:15 am

BTW, there is an error in the manual

Code: Select all

float Degrees Heading in degrees Counter-Clockwise (the way the rest of MQ2 and EQ uses it, and is expected by older macros)
Should be

Code: Select all

float [color=red]DegreesCCW[/color] Heading in degrees Counter-Clockwise (the way the rest of MQ2 and EQ uses it, and is expected by older macros)

srenex
orc pawn
orc pawn
Posts: 10
Joined: Sun Dec 28, 2003 3:49 am

Post by srenex » Sat Jun 12, 2004 4:06 am

That works, thanks!! My macro is working well now!


Edit: I had a question here, but I figured it out =)

Falco72
a hill giant
a hill giant
Posts: 215
Joined: Fri Sep 26, 2003 3:24 am

Post by Falco72 » Sat Jun 12, 2004 4:18 am

Using your example, "/macro ezw 70", change:

Code: Select all

Sub Main
/declare feettraveled int outer
/declare newx int outer
/declare newy int outer
/if (${Defined[Param0]}) {
   /varset feettraveled ${Param0}
} else {
   /varset feettraveled 50
}
BTW you no need to use #turbo, infact by default all macro are at turbo 20, so you need #turbo only if you want to set a different value (I mean, different from 20).