Game Maker's Garage Forum

Game Creation => GameMaker => Topic started by: Silverwind on September 01, 2008, 04:38:18 AM

Title: Gonna hang myself over this glitch...
Post by: Silverwind on September 01, 2008, 04:38:18 AM
I started making a simple Hang Man game last night, but now I'm stumped on a peculiar glitch. I think a repeat loop isn't repeating the correct amount of times. It seems to always repeat twice, even though it should repeat an amount of times equal to the length of the "sentence$" string variable.

Here's the source: http://www.mediafire.com/?o8dgyuqkzah

And here's the code: (this is the entire game's code. I've highlighted the area I think the glitch occurs in)

PICT CurrentCard

REPEAT
  sentence$ = USERASK Enter the name of a movie or book:
  sentence$ = UCASE$ sentence$
  block = 0
  IF sentence$ = "" THEN block = 1
  IF sentence$ = " " THEN block = 1
  IF sentence$ CONTAINS "." THEN block = 1
  IF sentence$ CONTAINS "," THEN block = 1
  IF sentence$ CONTAINS "/" THEN block = 1
  IF sentence$ CONTAINS "?" THEN block = 1
  IF sentence$ CONTAINS "'" THEN block = 1
  IF sentence$ CONTAINS ";" THEN block = 1
  IF sentence$ CONTAINS ":" THEN block = 1
  IF block = 0 THEN
    EXIT REPEAT
  ELSE
    ALERT The sentence must only contain letters and numbers.
  END IF
END REPEAT

blank$ = "_"
debug$ = ""
charactercheck$ = ""
characterchecknumber = 1
sentencelength = LEN sentence$
REPEAT
  charactercheck$ = MID$ sentence$ characterchecknumber 1
  IF charactercheck$ = " " THEN
    debug$ = debug$ + charactercheck$
  ELSE
    debug$ = debug$ + blank$
  END IF
  characterchecknumber = characterchecknumber + 1
  IF characterchecknumber > sentencelength THEN EXIT REPEAT
END REPEAT
PRINT $sentence$$ (length test)
PRINT
PRINT $debug$$ (length test)


ON KEYDOWN
  guess = 0
  keydown$ = UCASE$ keydown$
  IF keydown$ = "A" THEN guess = 1
  IF keydown$ = "B" THEN guess = 1
  IF keydown$ = "C" THEN guess = 1
  IF keydown$ = "D" THEN guess = 1
  IF keydown$ = "E" THEN guess = 1
  IF keydown$ = "F" THEN guess = 1
  IF keydown$ = "G" THEN guess = 1
  IF keydown$ = "H" THEN guess = 1
  IF keydown$ = "I" THEN guess = 1
  IF keydown$ = "J" THEN guess = 1
  IF keydown$ = "K" THEN guess = 1
  IF keydown$ = "L" THEN guess = 1
  IF keydown$ = "M" THEN guess = 1
  IF keydown$ = "N" THEN guess = 1
  IF keydown$ = "O" THEN guess = 1
  IF keydown$ = "P" THEN guess = 1
  IF keydown$ = "Q" THEN guess = 1
  IF keydown$ = "R" THEN guess = 1
  IF keydown$ = "S" THEN guess = 1
  IF keydown$ = "T" THEN guess = 1
  IF keydown$ = "U" THEN guess = 1
  IF keydown$ = "V" THEN guess = 1
  IF keydown$ = "W" THEN guess = 1
  IF keydown$ = "X" THEN guess = 1
  IF keydown$ = "Y" THEN guess = 1
  IF keydown$ = "Z" THEN guess = 1
  IF guess = 1 THEN
    guess$ = keydown$
    IF guessed$ CONTAINS guess$ THEN guess = 0
    guessed$ = guessed$ + guess$
  END IF

  IF guess = 1 THEN
    debug$ = ""
    charactercheck$ = ""
    characterchecknumber = 1
    sentencelength = LEN sentence$
    REPEAT
      charactercheck$ = MID$ sentence$ characterchecknumber 1
      IF charactercheck$ = " " THEN
        debug$ = debug$ + charactercheck$
      ELSE
        IF guessed$ CONTAINS charactercheck$ THEN
          debug$ = debug$ + charactercheck$
        ELSE
          debug$ = debug$ + blank$
        END IF
      END IF
      characterchecknumber = characterchecknumber + 1
      IF characterchecknumber > sentencelength THEN EXIT REPEAT
    END REPEAT
    CLEAR TEXT
    PRINT $sentence$$ (length test)
    PRINT
    PRINT $debug$$ (length test)
  END IF

  IF debug$ = sentence$ THEN
    ALERT You Win!
    GOTOCARD 2
  END IF
END KEYDOWN
Title: Re: Gonna hang myself over this glitch...
Post by: Al Staffieri on September 01, 2008, 07:30:15 AM
Strange. If you put the keydown code on another card then it works.
TD is having a problem with multiple REPEAT loops on a card too. I haven't been able to fix this fully yet. I keep trying.
Title: Re: Gonna hang myself over this glitch...
Post by: Silverwind on September 01, 2008, 09:50:58 AM
Thanks Al, that's a fine fix! :D I'll post the complete source and the compiled game later when I've added animations.
Title: Re: Gonna hang myself over this glitch...
Post by: Al Staffieri on September 07, 2008, 09:29:30 AM
OK. I found 2 problems in REPEAT loops. One should solve Silverwind's bug and the other should solve Tireas-Dragon's error in compiled games.

Silverwind:
There is still a bug that skips a line, but now it seems to skip the first line in the REPEAT loop of every REPEAT loop after the first one (2nd loop and all others).
Try this workaround and let me know if that fixes it.

REPEAT 3
 PRINT Loop 1
END REPEAT
REPEAT 3
  ' skip a line
  PRINT Loop 2
END REPEAT


Tireas-Dragon:
I found a typo in my engine for compiled games which caused the error. I wrote the wrong variable name in my code. I fixed the typo and I will send you an update to try. Also see above and make sure you skip a line after the REPEAT for now until I get that corrected.

Title: Re: Gonna hang myself over this glitch...
Post by: Tireas Dragon on September 07, 2008, 11:45:49 AM
Well that was very interesting. It doesn't say error contact maker of program anymore. But now when I get close to a wall it the one to the right is the same as the one to the left, but in run mode they both show up correctly. The interesting thing is that I know exactly what is happening, it just makes no sense that it happens in compiled but not run.  Oh and I did do that skip a line thing.
Title: Re: Gonna hang myself over this glitch...
Post by: Al Staffieri on September 07, 2008, 01:37:31 PM
OK. Thanks. I'm still working on it.
Title: Re: Gonna hang myself over this glitch...
Post by: Tireas Dragon on September 07, 2008, 05:32:58 PM
It's good to know that you are working on it.
Title: Re: Gonna hang myself over this glitch...
Post by: Silverwind on September 08, 2008, 02:47:40 AM
Yup, it's working great on my end Al. Thanks! :) It's exactly as you said, it skips the first line on every repeat block after the first.
Title: Re: Gonna hang myself over this glitch...
Post by: Al Staffieri on September 11, 2008, 08:04:46 AM
Both bugs are fixed for the next update.