if statement

Need help running MacroQuest2? Ask your questions about how to get things to work on your computer.

Moderator: MacroQuest Developers

rub
a lesser mummy
a lesser mummy
Posts: 40
Joined: Sun Feb 07, 2010 3:15 pm

if statement

Post by rub » Sun Dec 14, 2014 10:45 pm

I am trying to write a macro for my necro to fight along side my mage. For some reason I cannot get the if statement to run.

This works.
Sub Main

/declare Dist int outer ${Target.Distance}

:Check
/gsay ${Dist}
/goto :Check
/return

This does not.

Sub Main
/declare Dist int outer ${Target.Distance}

:Check
/if (${Dist}<30){
/gsay Target is in range
}else /if (${Dist}>30){
/gsay Target out of range
}
/return

Can someone help or point me in the right direction.
Error code.
Failed to parse /if command. Could not find command to execute.

Thanks in advance for any help

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: if statement

Post by dewey2461 » Mon Dec 15, 2014 12:00 am

First - use code blocks. [ code ] make things easier to follow.

Code: Select all

Sub Main
/declare Dist int outer ${Target.Distance}

:Check
   /varset Dist ${Target.Distance}  | <have to get new value inside the loop
   /if (${Dist}<30){
      /gsay Target is in range
   } else /if (${Dist}>30){
      /gsay Target out of range
   }
/return


Wolve
a lesser mummy
a lesser mummy
Posts: 69
Joined: Sun May 25, 2008 10:07 pm

Re: if statement

Post by Wolve » Tue Jan 27, 2015 12:59 pm

You need a space at the end of the /if statement before the bracket

Code: Select all

 
 /if (${Dist}<30){
to

Code: Select all

 /if (${Dist}<30) {
[quote="dont_know_at_all"]Don't be an at dollar dollar.[/quote]

ebzent
decaying skeleton
decaying skeleton
Posts: 9
Joined: Mon Feb 17, 2014 7:36 pm

Re: if statement

Post by ebzent » Mon Feb 02, 2015 1:10 pm

since your if statements have one command only after them, you could do:

Code: Select all

Sub Main
/declare Dist int outer ${Target.Distance}

:Check
   /varset Dist ${Target.Distance}  | <have to get new value inside the loop
   /if (${Dist}<=30) /gsay Target is in range
   /if (${Dist}>30) /gsay Target out of range
/return
Note that I added in an = in your check, so as to not leave a case where both /if statements will be false. There really isn't a need for the else, it will just keep rolling until an if statement is true.

If you have more lines to put in the if statements, use:

Code: Select all

Sub Main
/declare Dist int outer ${Target.Distance}

:Check
   /varset Dist ${Target.Distance}  | <have to get new value inside the loop
   /if (${Dist}<=30) {
      /gsay Target is in range
   }
   /if (${Dist}>30) {
      /gsay Target out of range
   }
/return