Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Using "Else If" statments

11 years ago

Is there a way in scripting to use the following:

If X
else if Y
else if Z

else W

Or is it not possible? 

Using "Else If" statments

11 years ago

Nope.

You can just use a bunch of IF statements though.

Using "Else If" statments

11 years ago

I need help then. I made a variable called KITCHENJ, which is just a counter that determines what page you should go on next. In the link, I added a reset for 1D10 for KITCHENJ. In the Script I did the following:

IF %KITCHENJ = 1
THEN $DEST := @P183
ELSE $DEST := @P182
 
IF %KITCHENJ = 2
THEN $DEST := @P185
ELSE $DEST := @P182
 
IF %KITCHENJ = 3
THEN $DEST := @P187
ELSE $DEST := @P182
 
Whenever I do it, however, it never executes 1 or 2. It just executes 3, or goes to page 182 if the value isn't 3.

Using "Else If" statments

11 years ago

You're partly right. It executes all three of them every time, but it overwrites the answer each time, so the result of the last one is the only one that matters.

Oh, by the looks of the code, IF ELSE is just chaining another if to it...haha.

So try:

IF %KITCHENJ = 1
THEN $DEST := @P183
IF %KITCHENJ = 2
THEN $DEST := @P185
IF %KITCHENJ = 3
THEN $DEST := @P187
ELSE $DEST := @P182
 
Nvm, that's wrong, one sec.

Using "Else If" statments

11 years ago

Hi Killa - fancy meeting you here at this time of night haha!  ^v^

Using "Else If" statments

11 years ago

The problem with stacking these is that the Script executes all of them - that means that it will only apply the last True statement - even if one above it was true first. You'll need this -

$DEST := @P182
IF %KITCHENJ = 1
THEN $DEST := @P183

IF %KITCHENJ = 2
THEN $DEST := @P185
 
IF %KITCHENJ = 3
THEN $DEST := @P187
 

Using "Else If" statments

11 years ago

Yeah, that's much better than the way I suggested haha.

Using "Else If" statments

11 years ago

You'll need to do a separate IF statement for all the other cases, in this case. So instead do:

IF %KITCHENJ = 1
THEN $DEST := @P183
 
IF %KITCHENJ = 2
THEN $DEST := @P185
 
IF %KITCHENJ = 3
THEN $DEST := @P187
 
IF %KITCHENJ = 4 OR %KITCHENJ = 5 OR %KITCHENJ = 6 OR %KITCHENJ = 7 OR %KITCHENJ = 8 OR %KITCHENJ = 9 OR %KITCHENJ = 10
THEN $DEST := @P182

Using "Else If" statments

11 years ago

Or this haha!

BEGIN
IF %KITCHENJ = 1
THEN $DEST := @P183
IF %KITCHENJ = 2
THEN $DEST := @P185
IF %KITCHENJ = 3
THEN $DEST := @P187
END
ELSE
$DEST := @P182

Using "Else If" statments

11 years ago

It worked, just as expected!

Thanks to the both of Killa_Robot and BerkaZerka for the help. It is very much appreciated!