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
-
OldNecro
- a ghoul

- Posts: 136
- Joined: Thu Dec 19, 2002 3:09 am
Post
by OldNecro » Thu Feb 26, 2004 7:38 pm
I want to do this:
/if blah1!=blah2 AND blah1!=blah3 {
dothiscrap
} else {
dothiscrap2
}
...without using a gagglefuck of /if statements
basically I am checking for valid parameters upon running a macro. if it doesn't match either of the possible options, it defaults.
Saddam Hussein begins to use An Innocent Bystander as a living shield!
An Innocent Bystander ceases protecting Saddam Hussein's corpse.
-
ml2517
- a grimling bloodguard

- Posts: 1216
- Joined: Wed Nov 12, 2003 1:12 am
Post
by ml2517 » Thu Feb 26, 2004 7:51 pm
Assuming your blah's were all string variables...
Code: Select all
/if ("@blah1"!="@blah2" && "@blah1"!="@blah3") {
dothiscrap
} else {
dothiscrap2
}
-
OldNecro
- a ghoul

- Posts: 136
- Joined: Thu Dec 19, 2002 3:09 am
Post
by OldNecro » Fri Feb 27, 2004 2:55 pm
outstanding. thx much for the syntax.
Saddam Hussein begins to use An Innocent Bystander as a living shield!
An Innocent Bystander ceases protecting Saddam Hussein's corpse.
-
lostcarrier
- decaying skeleton

- Posts: 9
- Joined: Wed Feb 25, 2004 7:05 pm
Post
by lostcarrier » Fri Feb 27, 2004 3:09 pm
Is it possible to use && and || on more than 2 concurrent comparisons? I have the following statement in a macro I'm working on.
Code: Select all
/if ("$spawn($group(@num),sclass)"=="WAR" || "$spawn($group(@num),sclass)"=="PAL" || "$spawn($group(@num),sclass)"=="SHD" || "$spawn($group(@num),sclass)"=="RNG") {
/dosomestuff
}
The problem is that the macro only processes the first two comparisons, i.e. it will /dosomestuff if the group member is a warrior or paladin, but not if it's a shadow knight or ranger. I've not been able to find a working example of a multiple OR in my code skimming, so any info would be appreciated.
CARRIER LOST
No connection.
-
Gumby
- a ghoul

- Posts: 99
- Joined: Sat Jan 24, 2004 5:27 pm
Post
by Gumby » Fri Feb 27, 2004 4:08 pm
lostcarrier wrote:Is it possible to use && and || on more than 2 concurrent comparisons? I have the following statement in a macro I'm working on.
Code: Select all
/if ("$spawn($group(@num),sclass)"=="WAR" || "$spawn($group(@num),sclass)"=="PAL" || "$spawn($group(@num),sclass)"=="SHD" || "$spawn($group(@num),sclass)"=="RNG") {
/dosomestuff
}
The problem is that the macro only processes the first two comparisons, i.e. it will /dosomestuff if the group member is a warrior or paladin, but not if it's a shadow knight or ranger. I've not been able to find a working example of a multiple OR in my code skimming, so any info would be appreciated.
Never tried and unfortunately not in a position to test, but for a quick fix assuming there is a limitation on it since your syntax looks right:
Code: Select all
/if ("$spawn($group(@num),sclass)"=="WAR" || "$spawn($group(@num),sclass)"=="PAL") {
/dosomestuff
} else {
/if ("$spawn($group(@num),sclass)"=="SHD" || "$spawn($group(@num),sclass)"=="RNG") {
/dosomestuff
}
}
G
-
lostcarrier
- decaying skeleton

- Posts: 9
- Joined: Wed Feb 25, 2004 7:05 pm
Post
by lostcarrier » Fri Feb 27, 2004 4:14 pm
Thanks for the suggestion. It would work if only I didn't already have an else statement after the comparisons.
CARRIER LOST
No connection.
-
lostcarrier
- decaying skeleton

- Posts: 9
- Joined: Wed Feb 25, 2004 7:05 pm
Post
by lostcarrier » Fri Feb 27, 2004 4:20 pm
Well, I got it working with multiple /if statements and several /goto points, but the code is very sloppy. If anyone knows about the limit on OR comparisons, I'd love to know about it. Thanks.
CARRIER LOST
No connection.
-
Gumby
- a ghoul

- Posts: 99
- Joined: Sat Jan 24, 2004 5:27 pm
Post
by Gumby » Fri Feb 27, 2004 4:33 pm
lostcarrier wrote:Thanks for the suggestion. It would work if only I didn't already have an else statement after the comparisons.
*chuckle* Then:
Code: Select all
/if ("$spawn($group(@num),sclass)"=="WAR" || "$spawn($group(@num),sclass)"=="PAL") {
/dosomestuff
} else {
/if ("$spawn($group(@num),sclass)"=="SHD" || "$spawn($group(@num),sclass)"=="RNG") {
/dosomestuff
} else {
/dosomethingelse
}
}
G
-
Gumby
- a ghoul

- Posts: 99
- Joined: Sat Jan 24, 2004 5:27 pm
Post
by Gumby » Fri Feb 27, 2004 4:49 pm
lostcarrier wrote:Well, I got it working with multiple /if statements and several /goto points, but the code is very sloppy. If anyone knows about the limit on OR comparisons, I'd love to know about it. Thanks.
Going to step out on a limb here since my C++ sucks badly..
EDIT: and I was wrong :). Thanks smelly.
G
Last edited by
Gumby on Sat Feb 28, 2004 8:25 am, edited 1 time in total.
-
smelly wang
- a lesser mummy

- Posts: 54
- Joined: Mon Jan 19, 2004 6:04 pm
Post
by smelly wang » Fri Feb 27, 2004 5:34 pm
You can have multiple and/or operators in it, just need to put brackets around 2 of them.
eg
Code: Select all
/if n ((A==1 || B==2) || C==3) { do this }
Thats the basic logic, which works for me. You'll have to figure out where to put the brackets and operators if you want to have || and && in one statement.
-
OldNecro
- a ghoul

- Posts: 136
- Joined: Thu Dec 19, 2002 3:09 am
Post
by OldNecro » Sat Feb 28, 2004 11:44 am
WHAT IF....
one of the comparisons is a string and the other is numeric? can those two be put on the same line, and if so, what is the syntax to get the "n" in there for the numeric comparison?
/if (string1==string2 && n num1==num2) maybe?
Saddam Hussein begins to use An Innocent Bystander as a living shield!
An Innocent Bystander ceases protecting Saddam Hussein's corpse.
-
Gumby
- a ghoul

- Posts: 99
- Joined: Sat Jan 24, 2004 5:27 pm
Post
by Gumby » Sat Feb 28, 2004 11:47 am
OldNecro wrote:
/if (string1==string2 && n num1==num2) maybe?
Got it in one.
G
-
ml2517
- a grimling bloodguard

- Posts: 1216
- Joined: Wed Nov 12, 2003 1:12 am
Post
by ml2517 » Sat Feb 28, 2004 2:23 pm
smelly wang wrote:You can have multiple and/or operators in it, just need to put brackets around 2 of them.
eg
Code: Select all
/if n ((A==1 || B==2) || C==3) { do this }
Thats the basic logic, which works for me. You'll have to figure out where to put the brackets and operators if you want to have || and && in one statement.
This is close, it would be more like this (Included a mix of numeric and string comparisons.):
Code: Select all
/if (((n @A==1 || n @B==2) || n @C==3) || "@Blah"=="@Blah2") { do this }
-
lostcarrier
- decaying skeleton

- Posts: 9
- Joined: Wed Feb 25, 2004 7:05 pm
Post
by lostcarrier » Sun Feb 29, 2004 6:14 am
Thanks everyone. Got it cleaned up and working great.
CARRIER LOST
No connection.