WatchNon-threaded

Forums » Advanced Editor Forum » Read Thread

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

Nested IF statements

9 years ago

What is the correct syntax for nesting?
Example:
Variable 1 and Variable 2 must equal 1 in order for the following text to appear "Syntax errors are so fun!"

Nested IF statements

9 years ago

Don't really needed to use nested IFs there, just do:

IF %variable1 = 0 AND %variable2 = 0 THEN

$PAGETEXT := $PAGETEXT + "Syntax errors are so fun!"

 

Nested IF statements

9 years ago

The above would normally be the way to go, but there is a current bug preventing the use of AND / OR Statements in the Script.

You can nest as deep as you want, but you have to balance out your BEGIN & ENDS:

IF %VARIABLE1 = 1 THEN
  BEGIN
  IF %VARIABLE2 = 1 THEN
    $PAGETEXT := $PAGETEXT + "Syntax errors are so fun!"
  END

 

Nested IF statements

9 years ago

Bug?

I have a script that uses AND and it works fine.

Nested IF statements

9 years ago

I haven't tried to use AND in at least eight months, maybe it's fixed, or I was trying to use it wrong, but I do recall talking about the problem within the last five months at least.

I'll have to try it here and see if it works for me now too. That would be incredibly helpful!

Nested IF statements

9 years ago

I've finally got the AND / OR Syntax right and it works for me now. Of course I recommend using that over deep-nesting of simple statements, but knowing how to do it is still important  ^_^

Nested IF statements

9 years ago

Here’s a sample of deep-nesting I used to resolve the following BITE/ INFECTION/WARNED combinations:

BITES = 0; INFECTION < 2
BITES = 0; INFECTION = 2
BITES > 0; INFECTION; < 2 WARNED = 0
BITES > 0; INFECTION; = 2 WARNED = 0
BITES > 0; INFECTION; < 2 WARNED = 2
BITES > 0; INFECTION; = 2 WARNED = 2

Basically, I want it to check if the player has Bites or not, then if he’s been Infected, and finally, if he has been Warned about the Infection (only if he has it). Note the nesting levels by color. Red text annotation only, do not include in Script.

IF %BITES = 0 THEN
BEGIN
IF %INFECTION < 2 THEN
  $DEST := @P1688 (not bit, not infected)
IF %INFECTION = 2 THEN
  $DEST := @P1689 (not bit, but infected)
END

IF %BITES > 0 THEN
BEGIN
IF %WARNED = 0 THEN
BEGIN
IF %INFECTION < 2 THEN
  $DEST := @P1690 (bit, not infected, not warned)
IF %INFECTION = 2 THEN
  $DEST := @P1691 (bit and infected, but not warned)
END
IF %WARNED = 2 THEN
BEGIN
IF %INFECTION < 2 THEN
  $DEST := @P1688 (bit, not infected, warned)
IF %INFECTION = 2 THEN
  $DEST := @P1689 (bit and infected and warned)
END
END

Nested IF statements

9 years ago

If that's one of your real scripts, then shouldn't:

$DEST := @P1688 (not bit, not infected)

$DEST := @P1688 (bit, not infected, warned)

Both leading to the same page, but meaning very different things, be an error? Or do you modify the page text on the page?

And why no love for ELSE statements? Lol

Nested IF statements

9 years ago

Good catch, but yeah, in that case, it was the same page with different text showing based on the Variable values.

I do occasionally use the ELSE Statement, but in this case, specifically wanted to show multi-levels of nesting  =)