Topic:   Umm...   (Read 9907 times)


0 Members and 1 Guest are viewing this topic.

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Umm...
« on: March 12, 2011, 07:02:06 PM »
IF an IF is inside an IF, is it proper to END IF twice?

ON KEYDOWN
IF keydown$ = "1" THEN
IF turn = 0 THEN
x = RANDOM 2
IF x = 2 THEN ALERT Success!
ELSE
ALERT Failed.
turn = 1
END IF
END IF

This doesn't work. What's wrong?

Just making a simple adventure game.
-zoo
P.S. Don't tell webmaster
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Umm...
« Reply #1 on: March 12, 2011, 07:38:36 PM »
Try indenting your code. Really helps with finding errors:
Code: [Select]
ON KEYDOWN 
      IF keydown$ = "1" THEN  
            IF turn = 0 THEN
                  x = RANDOM 2
                  IF x = 2 THEN ALERT Success!
            ELSE
                  ALERT Failed.
                  turn = 1
            END IF
      END IF
Seems to me like you're missing an end keydown.

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Umm...
« Reply #2 on: March 12, 2011, 08:12:59 PM »
Hmm. This is quite confusing. I've checked it many times and added the end keydown. but still not working.
« Last Edit: March 12, 2011, 08:15:19 PM by zoo804 »
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Umm...
« Reply #3 on: March 13, 2011, 12:49:18 AM »
I tried it as well and the ELSE condition never executes. Very strange...
I survived the spammage of 2007

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: Umm...
« Reply #4 on: March 13, 2011, 09:16:13 AM »
Looks like it's a problem with your turn variable. It will never = 1. See below.


' assume turn = 0 at start
ON KEYDOWN
  ' key 1 pressed
  IF keydown$ = "1" THEN
    ' turn = 0 so do this
    IF turn = 0 THEN
      x = RANDOM 2
      IF x = 2 THEN ALERT Success!
    ELSE
      ' turn will never be anything other than 0 so will never get here
      ' turn needs to be set to 1 or something other than 0 to get here.
      ALERT Failed.
      turn = 1
    END IF
  END IF
END KEYDOWN