Non-threaded

Forums » Advanced Editor Forum » Read Thread

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

Multiple "if / then" in script doesn't work

3 years ago

I've tried to add a script to a link, but it doesn't work. The goal is, when the player clicks on a link, a variable change : from 1 to 4, 2 to 1, 3 to 2, 4 to 3 (but the player remains on the same page). So i've written that in the script:

IF %VARIABLE1 = 2
THEN %VARIABLE1 := 1

IF %VARIABLE1 = 3
THEN %VARIABLE1 := 2

IF %VARIABLE1 = 4
THEN %VARIABLE1 := 3

IF %VARIABLE1 = 1
THEN %VARIABLE1 := 4

It works… except for "2 to 1"! Instead, the 2 goes to 4.

Why? And how to fix this?

Multiple "if / then" in script doesn't work

3 years ago
I can't test it right now but I'm guessing that the first check sets it to 1, then the last sees that it's 1 and sets it to 4. Try changing the order?

Multiple "if / then" in script doesn't work

3 years ago

Indeed! I moved "2 to 1" to the end, and now it's "3 to 2" that doesn't work… It looks like the first one is always skipped!

Multiple "if / then" in script doesn't work

3 years ago
Well not so much skipped as replaced. It just checks each of them in order, the variable is getting changed twice.

Multiple "if / then" in script doesn't work

3 years ago

Is there some way to avoid this?

Multiple "if / then" in script doesn't work

3 years ago
It looks like you're just moving the number over by one, so try this:

%VARIABLE1 = %VARIABLE1 - 1

IF %VARIABLE1 = 0
THEN %VARIABLE1 := 4

Multiple "if / then" in script doesn't work

3 years ago

It works!! Thank you very much ^^

Multiple "if / then" in script doesn't work

3 years ago
Glad my tactic of stalling until somebody else showed up worked out.

Multiple "if / then" in script doesn't work

3 years ago

So thank you too for your stalling xDD