Game Maker's Garage Forum
Game Creation => GameMaker => Topic started 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
-
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.
-
Thanks Al, that's a fine fix! :D I'll post the complete source and the compiled game later when I've added animations.
-
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.
-
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.
-
OK. Thanks. I'm still working on it.
-
It's good to know that you are working on it.
-
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.
-
Both bugs are fixed for the next update.