Main loop refuses to identify Repeat?

BlitzMax Forums/BlitzMax Beginners Area/Main loop refuses to identify Repeat?

Omni(Posted 2006) [#1]
I know I must be doing something stupid here. I made a larger program, but it's mostly just a text adventure type thing with a lot of drawtext lines. I simplified it a bit but the rest of the code is the same.

SetGraphicsDriver GLMax2DDriver()
AppTitle = "More like TEST adventure"
Graphics 400,300,0,60

Local font:TImageFont=LoadImageFont("C:\WINDOWS\Fonts\arial.ttf",16)
SetImageFont(font)

SeedRnd MilliSecs()

Repeat
	Cls
	DrawText "How do you respond?", 100, 140
	DrawText "(Y = ~qYes!~q / N = ~qNo!~q)", 100, 160
	Flip
		Repeat
		Until KeyDown(KEY_Y) Or KeyDown(KEY_N)
	If KeyDown(KEY_N) Then
		Repeat
			Cls
			blinkR = Rnd(255)
			blinkG = Rnd(255)
			blinkB = Rnd(255)
			DrawText "YOU WIN!", 100, 140
			SetColor blinkR,blinkG,blinkB
			DrawText "Play Again?", 90, 180
			Flip
		Until KeyDown(KEY_Y) Or KeyDown(KEY_N)
	Else
		Repeat
			Cls
			DrawText "YOU LOSE!" 100, 140
			DrawText "Play Again? (Y)es/(E)xit" 70, 180
			Flip
		Until KeyDown(KEY_Y) Or KeyDown(KEY_E)
	If KeyDown(KEY_Y) Then Exit
Until KeyDown(KEY_E)

End

Notice how I used the flashy color code for "You Win!" from one of the beginner tutorials. Isn't that just adorable?

Anyways the compile error I get is "'Until' without matching 'Repeat'", but there are just as many repeats to match all the untils I am using. What gives?


Dreamora(Posted 2006) [#2]
Endif is missing after the "you lose" repeat part. You have a new if there but no endif to close the KEY_N if block for that reason the last until can't be recognized as well.


Omni(Posted 2006) [#3]
Haha. Told you it was a stupid mistake :/
Aside from a couple missing commas I got it all working after that. Also it responds too fast if someone holds down the key nothing a few delays couldn't fix. Thanks!


GfK(Posted 2006) [#4]
use KeyHit() instead of KeyDown().


Omni(Posted 2006) [#5]
I tried KeyHit() and it just leads to the You Lose! screen everytime and somehow doens't break out of the main loop either. So in other words it seems to be taking the input as if I'm pressing "N" then "Y" each time... odd


Dubious Drewski(Posted 2006) [#6]
Hey Omni. Not sure if you care about this anymore, but I thought I'd give my input.
I think you had troubles for three reasons:

1. You used a loop embedded within a loop, with both using KEY_Y and KEY_N. So
because you used Key_Down instead of key_hit, your program flow becomes uncontrollable.

2. You have too many nested loops. Check out my code to see what I changed there.

3. Your indentation system is wonky, sorry man. That's likely why you missed the 'Endif'.
I really had to think in order to follow your code. No biggie, though.

AppTitle = "More like TEST adventure"
Graphics 400,300,0,60
Local font:TImageFont=LoadImageFont("C:\WINDOWS\Fonts\arial.ttf",16)
SetImageFont(font)

Repeat
	DrawText "How do you respond?  1 or 2", 100, 140
	DrawText "Hit e to exit", 100, 160
	Flip;cls
	If KeyHit(KEY_1) Then
		Repeat
			DrawText "YOU LOSE!", 100, 140
			DrawText "Play again? Y/N", 100, 160
			Flip;Cls
			If KeyHit(KEY_N) End
		Until KeyHit(KEY_Y)
	ElseIf KeyHit(KEY_2) Then
		Repeat
			SetColor Rnd(255), Rnd(255), Rnd(255)
			DrawText "YOU WIN!", 100, 140
			SetColor 255, 255, 255
			DrawText "Play again? (Y/N)", 100, 160
			Flip;Cls
			If KeyHit(KEY_N) End
		Until KeyHit(KEY_Y)
	EndIf
Until KeyDown(KEY_E)


I completely changed the structure so that it's simpler and easier to follow. I hope you get something from this.