WatchNon-threaded

Forums » Advanced Editor Forum » Read Message

Talk about it. Ask for help on it. Compliment it.

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

7 months 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

7 months 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

7 months 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

7 months 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

7 months ago

Is there some way to avoid this?

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

7 months 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

7 months ago

It works!! Thank you very much ^^

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

7 months ago
Glad my tactic of stalling until somebody else showed up worked out.

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

7 months ago

So thank you too for your stalling xDD