Topic:   SELECT CASE help   (Read 19753 times)


0 Members and 2 Guests are viewing this topic.

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
SELECT CASE help
« on: September 02, 2011, 08:47:30 PM »
ON TIMER 10
  mytimer = mytimer + 1
  IF mytimer > 3 THEN mytimer = 1
  SELECT CASE myTimer
    CASE 1
ai = RANDOM 1 2 3 4
IF ai = 1 THEN x = x + 20
IF ai = 2 THEN x = x - 20
IF ai = 3 THEN y = y + 20
IF ai = 4 THEN y = y - 20
SPRITE 1 x y block2.gif


This is a script I wrote a long time ago for a sprite that ran around randomly. It worked in a different game, but when I copied it into a new one, it gave me an error message "Nested SELECT CASE not allowed" I'm sure there's a simple solution, but I have never used the SELECT CASE command before, and I'm still a noob at GM.
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: SELECT CASE help
« Reply #1 on: September 02, 2011, 11:48:39 PM »
You have to make sure you end the blocks with END SELECT and END TIMER

ON TIMER 10
  mytimer = mytimer + 1
  IF mytimer > 3 THEN mytimer = 1
  SELECT CASE myTimer
    CASE 1
    ai = RANDOM 1 2 3 4
    IF ai = 1 THEN x = x + 20
    IF ai = 2 THEN x = x - 20
    IF ai = 3 THEN y = y + 20
    IF ai = 4 THEN y = y - 20
    SPRITE 1 x y block2.gif
  END SELECT
END TIMER


If you are only checking for 1 case then it may be better to use IF

ON TIMER 10
  mytimer = mytimer + 1
  IF mytimer > 3 THEN mytimer = 1
  IF mytimer = 1 THEN
    ai = RANDOM 1 2 3 4
    IF ai = 1 THEN x = x + 20
    IF ai = 2 THEN x = x - 20
    IF ai = 3 THEN y = y + 20
    IF ai = 4 THEN y = y - 20
    SPRITE 1 x y block2.gif
  END IF
END TIMER

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: SELECT CASE help
« Reply #2 on: September 03, 2011, 09:11:29 AM »
Wow thanks! If you're wondering, I'm making a test game about running around collecting coins and avoiding walls and enemies.
« Last Edit: September 03, 2011, 09:18:57 AM by zoo804 »
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: SELECT CASE help
« Reply #3 on: September 03, 2011, 09:26:53 AM »
Ok, I've found another problem, The coin spawn code and the enemy code won't work together. The coin spawning works, but the enemy won't move.




Code: [Select]
ON TIMER 10
  mytimer = mytimer + 1
  IF mytimer > 3 THEN mytimer = 1
  IF mytimer = 1 THEN
    ai = RANDOM 1 2 3 4
    IF ai = 1 THEN x1 = x1 + 50
    IF ai = 2 THEN x1 = x1 - 50
    IF ai = 3 THEN y1 = y1 + 50
    IF ai = 4 THEN y1 = y1 - 50
    SPRITE 3 x1 y1 block2.gif  
  END IF
END TIMER



ON TIMER 100
  mytimer2 = mytimer2 + 1
  IF mytimer2 > 3 THEN mytimer2 = 1
  IF mytimer2 = 1 THEN
csX = RANDOM 626
csY = RANDOM 327
SPRITE 4 csX csY coin.gif
  END IF
END TIMER
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: SELECT CASE help
« Reply #4 on: September 03, 2011, 11:18:11 AM »
You can only have 1 active timer. Try this:

ON TIMER 15
  mytimer = mytimer + 1
  IF mytimer = 2 THEN
    ai = RANDOM 1 2 3 4
    IF ai = 1 THEN x1 = x1 + 50
    IF ai = 2 THEN x1 = x1 - 50
    IF ai = 3 THEN y1 = y1 + 50
    IF ai = 4 THEN y1 = y1 - 50
    SPRITE 3 x1 y1 block2.gif
    mytimer = 0
  END IF

  mytimer2 = mytimer2 + 1
  IF mytimer2 = 7 THEN
    csX = RANDOM 626
    csY = RANDOM 327
    SPRITE 4 csX csY coin.gif
    mytimer2 = 0
  END IF
END TIMER  


Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: SELECT CASE help
« Reply #5 on: September 03, 2011, 09:13:18 PM »
Ah, thanks, I always forget things like that.
Kirby, your pudgy buddy from dream land, is back again on the game boy®!