|
tigika Newbie
Joined: 30 Oct 2003 Posts: 7
|
Posted: Fri Oct 31, 2003 6:55 am
nested ifs? |
How does nested ifs work in zmud? Since the case statments is based on numericals so couldn't use that.
From what I understand the 2nd {} is the else option so if I put another #IF statment in there it should run but zmud doesn't and reports it as error.
I'm trying to setup a value based on the diagnoise of the mob.
any help is appricated.
(part of code)
#IF (@enemy_status = "healthy") {#var emy_st 100}
{#IF (@enemy_status = "burised") {#var emy_st 80}
{#IF (@enemy_status = "scraped") {#var emy_st 60}
{#IF (@enemy_status = "bleeding") {#var emy_st 40}
{#IF (@enemy_status = "gushing") {#var emy_st 20}
{#IF (@enemy_status = "") {#var emy_st 0}
}
}
}
}
} |
|
|
|
Carabas GURU
Joined: 28 Sep 2000 Posts: 434 Location: USA
|
Posted: Fri Oct 31, 2003 7:35 am |
Unless @enemy_status can be, for example, healthy and gushing at the same time, there should really be no need to nest those if statements.
Lets say for example, @enemy_status were equal to "scraped" and @emy_st were 0.
#IF (@enemy_status = "healthy") {#var emy_st 100} false, emy_st=0
#IF (@enemy_status = "burised") {#var emy_st 80} false, emy_st=0
#IF (@enemy_status = "scraped") {#var emy_st 60} true, emy_st=60
#IF (@enemy_status = "bleeding") {#var emy_st 40} false, emy_st=60
#IF (@enemy_status = "gushing") {#var emy_st 20} false, emy_st=60
#IF (@enemy_status = "") {#var emy_st 0} false, emy_st=60
As you can see, nesting the if statements would only add a level of confusion to the code. The end result (that is, the value of emy_st) would be the same.
However, to answer your question. For the If-Then-Else to work, the closing curly bracket for the true command must immediately precede the opening curly bracket for the false command.
Like this:
#IF (@enemy_status = "healthy") {
#var emy_st 100
} {
#IF (@enemy_status = "bruised") {
#var emy_st 80
} {
#IF (@enemy_status = "scraped") {
#var emy_st 60
} {
#IF (@enemy_status = "bleeding") {
#var emy_st 40
} {
#IF (@enemy_status = "gushing") {
#var emy_st 20
} {
#IF (@enemy_status = "") {
#var emy_st 0
}
}
}
}
}
}
Or this:
#IF (@enemy_status = "healthy") {#var emy_st 100} {
#IF (@enemy_status = "bruised") {#var emy_st 80} {
#IF (@enemy_status = "scraped") {#var emy_st 60} {
#IF (@enemy_status = "bleeding") {#var emy_st 40} {
#IF (@enemy_status = "gushing") {#var emy_st 20} {
#IF (@enemy_status = "") {#var emy_st 0}
}
}
}
}
} |
|
|
|
hatespyware Apprentice
Joined: 16 Dec 2002 Posts: 103
|
Posted: Fri Oct 31, 2003 8:12 am |
It also seems to be true that the first opening brace needs to be on the first line... this is counterintuitive for me, too (and much harder to read, since you can't use indentation to indicate nest depth).
Code: |
if(outer)
{
if(inner)
{
}
}
|
I'd also like to piggyback a related question onto yours. How do nested loops work? Unlike traditional for loops where you can specify the counter variable, zMud just gives you %i. How do you access the outer loop's %i? |
|
|
|
hatespyware Apprentice
Joined: 16 Dec 2002 Posts: 103
|
Posted: Fri Oct 31, 2003 8:14 am |
Of course, I guess we could just use zMud's vbscript/jscript caps :)
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Oct 31, 2003 8:31 am |
From version history for version 6.56. Not sure when the additional loopvariables were introduced, but they've been around for awhile.
%i, %j, %k, etc loop variables are now expanded EARLY, similar to %1..%99 variables. This means than when using nested loops, you MUST use %j instead of %i to refer to the innermost loop. This could break existing scripts that were not using %i and %j correctly. Additional variables such as %k, %l, %m... can be used for additional nested loops. The %repeatnum variable is still expanded late as before and can be used to reference the innermost loop if backwards compatibility is needed. |
|
|
|
hatespyware Apprentice
Joined: 16 Dec 2002 Posts: 103
|
Posted: Fri Oct 31, 2003 5:57 pm |
Cool... you're very correct. Just verified (6.62) that nested loops work just like you said. Thank you. Would probably be worth mentioning somewhere in the docs.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Oct 31, 2003 11:52 pm |
As an alternative, you could indeed use #case for this task. You just need to include %ismember() as the condition, which will return either a zero (in which case the #CASE aborts without effect) or the list item number (first item is 1, second is 2, etc). This can then be the number required for #CASE:
#CASE %ismember(@enemy_status,"healthy|bruised|scraped|bleeding|gushing|") {{#var emy_st 100} {{#var emy_st 80} {{#var emy_st 60} {{#var emy_st 40} {{#var emy_st 20} {{#var emy_st 0}
The difference wouldn't be at all noticeable on a small code snippet, but you're cutting down operations from 6 condition checks to just a single one. |
|
|
|
|
|