## News:

*NEW* Current Version on STEAM16.793

Webchat:
Visit the chat

## Making a simple game work

#### Sev

Hi again,

I am creating a very simple educational game for my assignment and i need help with getting sums to be answered correctly and incorrectly and then progressing to the next sum.

This is the code which doesnt work and i would like to know how to make sum able to be answered and then progress or finish the game:

Code (glbasic) Select
`FUNCTION themaingame:WHILE TRUE PRINT "START THE GAME HERE", 100, 100 LOCAL answer% PRINT "2+1=",100,150 INPUT value% IF value% = 3 IF value% = >3 IF value% = < 3 SHOWSCREENWENDENDFUNCTION`

Any help will be appreciated, thanks
Red Text

#### Darmakwolf

#1
DARMAKWOLF TO THE RESCUE!

see attached project.

Let me explain my code.

Code (glbasic) Select
`SETCURRENTDIR("Media")SETTRANSPARENCY RGB(255,0,255)LOADFONT "edufont.png",0SETFONT 0WHILE TRUELOCAL num1% //Defines a numberLOCAL num2% //Defines another numberLOCAL answer% //Holds our answerSTATIC numcorrect% = 0  //Holds how many we have correctnum1 = RND(25)  //Generate a random number between 0 and 25 for our first numbernum2 = RND(25) //Generate a random number between 0 and 25 for our second numberredo: //This is a label. You can use GOTO to hop back to here in code.PRINT "Welcome to Sums! " + numcorrect + " correct so far.",5,5 //Print our welcome message with the number we have completedPRINT num1 + " + " + num2 + " = ",5,35 //Displays our problem to solve. As you can see, it calls variables num1 and num2INPUT answer,160,35 //This is the simple INPUT command to draw user input.IF INTEGER(num1 + num2) = answer //This IF statement checks whether or not num1+num2 = answerCLEARSCREEN //Clears the screenPRINT "CORRECT!",5,5 //Prints CORRECT!INC numcorrect,1 //Increase correct problems by 1SHOWSCREEN //Draw the screenSLEEP 2000 //Freezes the screen for 2 secondsELSE //ELSE... means the user failed the question. num1 + num2 is not answer.CLEARSCREEN //Clears the screenPRINT "SORRY! TRY AGAIN!",5,5 //Prints SORRY! TRY AGAIN!SHOWSCREEN //Draw the screenSLEEP 2000 //Freezes the screen for 2 secondsGOTO redo //GOTO our redo label we made earlier to retry the questionENDIF //ENDIF ends the IF statementSHOWSCREENWEND`

#### Sev

Thanks DARMAKWOLF
Red Text

#### Darmakwolf

More than welcome, friend! Ask me if you need any more help!

#### Sev

@Darmakwolf In regards to the above code how do you tell the game to only redo the sums tens times.
Red Text

#### mentalthink

#5
Hi Sev, sorry I'm not sure if you want the code only ask 10 times the question?¿... My English it's very poor, too many times  Sorry.

Well if it's this it's very easy you only have to add a counter...

Code (glbasic) Select
`SETCURRENTDIR("Media")SETTRANSPARENCY RGB(255,0,255)LOADFONT "edufont.png",0SETFONT 0WHILE TRUELOCAL num1% //Defines a numberLOCAL num2% //Defines another numberLOCAL answer% //Holds our answerSTATIC numcorrect% = 0  //Holds how many we have correctGLOBAL counter_Times=0   //This it's the variable for count how many times the program makes the Questionnum1 = RND(25)  //Generate a random number between 0 and 25 for our first numbernum2 = RND(25) //Generate a random number between 0 and 25 for our second numberredo: //This is a label. You can use GOTO to hop back to here in code.PRINT "Welcome to Sums! " + numcorrect + " correct so far.",5,5 //Print our welcome message with the number we have completedPRINT num1 + " + " + num2 + " = ",5,35 //Displays our problem to solve. As you can see, it calls variables num1 and num2//New COdeif counter_Times<=10    INC counter_Times, 1   //This last parameter 1, don't it's needed it¡s the same -"INC counter_Times" () only when you add 1.    INPUT answer,160,35 //This is the simple INPUT command to draw user input.ELSE    CLEARSCREEN    PRINT "THE PROGRAM ENDS",0,0    SHOWSCREEN    SLEEP 2500    ENDENDIFIF INTEGER(num1 + num2) = answer //This IF statement checks whether or not num1+num2 = answerCLEARSCREEN //Clears the screenPRINT "CORRECT!",5,5 //Prints CORRECT!INC numcorrect,1 //Increase correct problems by 1SHOWSCREEN //Draw the screenSLEEP 2000 //Freezes the screen for 2 secondsELSE //ELSE... means the user failed the question. num1 + num2 is not answer.CLEARSCREEN //Clears the screenPRINT "SORRY! TRY AGAIN!",5,5 //Prints SORRY! TRY AGAIN!SHOWSCREEN //Draw the screenSLEEP 2000 //Freezes the screen for 2 secondsGOTO redo //GOTO our redo label we made earlier to retry the questionENDIF //ENDIF ends the IF statementSHOWSCREENWEND`