Text Problems
Blitz3D Forums/Blitz3D Beginners Area/Text Problems
| ||
I am making a simple math game and it tells you if you are right or wrong. The problem is it says i'm wrong every time unless I type in the same number every time until it finally says right. I think it has something to do with the Rnd(0,9) code because I put instead of Rnd, just 5, and when I typed in 10 it said I was right. Here's the code: Graphics 800,600 planetmath=LoadImage("planetmath.bmp") beep=LoadSound("beep.wav") beeplow=LoadSound("beeplow.wav") SetBuffer BackBuffer() font=LoadFont("Impact",72,True,False) SetFont font While Not KeyHit(1) SeedRnd MilliSecs() number1=Rnd(0,9) number2=Rnd(0,9) DrawImage planetmath,0,0 Color 0,0,0 Text 430,320,number1 Text 493,325,"+" Text 557,320,number2 Text 609,325,"=" Color 0,255,0 If number1+number2=guess Then Text 600,410,"Right" PlaySound beep Else Color 255,0,0 Text 600,410,"Wrong" PlaySound beeplow EndIf Locate 660,320 guess=Input("") Flip Cls Wend -thanks |
| ||
Code is executed from TOP to BOTTOM. Your check if the answer is right comes BEFORE the user has typed it in. SO, guess will always equal 0 when the check occurs. Move the two lines: Locate 660, 320 guess = Input("") before the line: If number1+number2=guess Then |
| ||
That still does not work :( I put the Locate 660, 320 guess = Input("") before the If number1+number2=guess Then and it still does not work. |
| ||
Po, Try this Graphics 800,600 planetmath=LoadImage("planetmath.bmp") beep=LoadSound("beep.wav") beeplow=LoadSound("beeplow.wav") SetBuffer BackBuffer() font=LoadFont("Impact",72,True,False) SetFont font While Not KeyHit(1) Cls SeedRnd MilliSecs() number1=Rnd(0,9) number2=Rnd(0,9) DrawImage planetmath,0,0 Color 0,255,0 Text 430,320,number1 Text 493,325,"+" Text 557,320,number2 Text 609,325,"=" Color 0,255,0 Locate 400,340 guess=Input("Input your guess using the top number keys:-") If number1+number2=guess Then Text 600,410,"Right" PlaySound beep Else Color 255,0,0 Text 600,410,"Wrong" PlaySound beeplow EndIf Color 0,255,0 Locate 600,430 again$=Input("Try Another? y / n ") If again$="n" End EndIf Flip Wend It seems to work if you enter your number from the top number row on your keyboard, so leave the number pad alone!!. Luna. |
| ||
hmmmm... the above code is the same as the code I have now except for the: Color 0,255,0 Locate 600,430 again$=Input("Try Another? y / n ") If again$="n" End which I don't really need anyways. I'ts odd how this is not working... I made a perfectly working one a while ago like it, The code was: AppTitle "Math Master 2000" SetBuffer BackBuffer() Graphics 800,600 mm=LoadImage("mm.bmp") DrawImage mm, 50,0 Print "Please Wait...." Delay 2000 Cls DrawImage mm, 50,0 While Not KeyHit(1) .startgame Locate 0,0 wrong=0 For turn= 0 To 9 Cls DrawImage mm, 50,0 SeedRnd MilliSecs() sndno1=Rnd(0,99) sndno2=Rnd(0,99) sndanswer=sndno1+sndno2 Print sndno1+" + "+sndno2 guess=Input("=") sndbeep=LoadSound ("beep.wav") sndbeeplow=LoadSound ("beeplow.wav") SoundVolume sndbeeplow,1 sndmtruc=LoadSound ("mtruc.wav") If guess=sndanswer Then Color 0,255,0 Print "Correct" PlaySound sndbeep Else ;guess not = sndanswer wrong=wrong+1 Color 255,0,0 Print "WRONG!" Print "A: "+sndanswer PlaySound sndbeeplow EndIf ;guess=sndanswer WaitKey() PlaySound sndmtruc Next Cls DrawImage mm, 50,0 Color 0,255,255 Print "You got "+wrong+" wrong out of 10 questions." If wrong= 0 Then Print "Your grade: A+" EndIf If wrong=1 Or wrong=2 Then Print "Your grade: A" EndIf If wrong=3 Or wrong=4 Then Print "Your grade: B" EndIf If wrong=5 Then Print "Your grade: C" EndIf If wrong>5 Then Print "Your grade: F" EndIf Color 255,0,255 Print "Press any key for another game, <Esc> to exit to" Print "main menu." key = WaitKey() Wend StopChannel chnMusicLoop If Not key = 27 Cls DrawImage mm, 50,0 Goto startgame EndIf I don't see why the code I have now won't work. |
| ||
Po, Your correct your old code does work but it is exactly the same. If you enter numbers from the number pad Blitz seems to ignore them?. I think I will have a look through the other posts and see if this has been reported as a bug. Luna. |