Hi everyone I need help for a timer with MY new game. The timer goes to the negatives and I need it so when it goes to zero it will go to the title screen.
Heres my code:
#CONSTANT TRUE = 1
#CONSTANT FALSE = 0
#CONSTANT MODE_TITLE = 1
#CONSTANT MODE_INSTRUCTIONS = 2
#CONSTANT MODE_SUBJECT_SELECT = 3
#CONSTANT MODE_MATH_TEST = 4
#CONSTANT MODE_HISTORY_TEST = 5
Type TestQuestion
question as string
choice1 as string
choice2 as string
choice3 as string
choice4 as string
answer as integer
EndType
rem read the math questions data into the math array
restore MathQuestions
read size
dim math(size) as TestQuestion
for i = 1 to size
read math(i).question
read math(i).choice1
read math(i).choice2
read math(i).choice3
read math(i).choice4
read math(i).answer
next i
rem read the history questions data into the history array
restore HistoryQuestions
read size
dim history(size) as TestQuestion
for i = 1 to size
read history(i).question
read history(i).choice1
read history(i).choice2
read history(i).choice3
read history(i).choice4
read history(i).answer
next i
rem read the history questions data into the history array
restore ScienceQuestions
read size
dim science(size) as TestQuestion
for i = 1 to size
read science(i).question
read science(i).choice1
read science(i).choice2
read science(i).choice3
read science(i).choice4
read science(i).answer
next i
set text font "arial"
rem set default mode to display opening title
mode = MODE_TITLE
do
cls
if mode = MODE_TITLE then gosub Title
if mode = MODE_INSTRUCTIONS then gosub Instructions
if mode = MODE_SUBJECT_SELECT then gosub SubjectSelect
if mode = MODE_MATH_TEST then gosub MathTest
if mode = MODE_HISTORY_TEST then gosub HistoryTest
if mode = MODE_SCIENCE_TEST then gosub ScienceTest
if inkey$() = "" then kFlag = 0
rem Display timer only during the test
if startTest = TRUE and finishedTest = FALSE
elapsedTime = (timer() - startingTime) / 1000
timeLeft = gameTime - elapsedTime
Text 20, 20, "Seconds Left: "+str$(timeLeft)
endif
loop
Title:
set text size 30 : ink rgb (255,255,255),0
center text 320,60, "Welcome to Edumania!"
set text size 15
center text 320,160, "Press X if you don't want to read the instructions"
center text 320,180, "Press H if you want to read the instructions"
if inkey$() = "x" and kFlag = 0 then mode = MODE_SUBJECT_SELECT : kFlag = 1
if inkey$() = "h" and kFlag = 0 then mode = MODE_INSTRUCTIONS : kFlag = 1
RETURN
Instructions:
ink rgb (0,255,0),0 : set text size 30
center text 320,60, "Instructions"
ink rgb (255,255,255),0
set text size 15
Center text 320,160, "Welcome to the Edumania Test Prep! In this Game"
center text 320,180, "you have to answer as many problems as you can"
center text 320,200, "before the timer runs out."
center text 320,220, "Good Luck!"
ink rgb (0,255,0),0
center text 320,420, "Press SPACE to start"
center text 320,400, "Press B to go back"
if inkey$() = "b" and kFlag = 0 then mode = MODE_TITLE : kFlag = 1
if spacekey() = 1 and kFlag = 0 then mode = MODE_SUBJECT_SELECT : kFlag = 1
RETURN
SubjectSelect:
ink rgb (255,255,255),0 : set text size 30
center text 320,200,"Which subject do you want to select?"
set text size 15
text 240,280,"1.)Math"
text 240,300,"2.)History"
text 240,320,"3.)Science"
center text 320,380, "Press B to go back"
startTest = FALSE
if inkey$() = "1" and kFlag = 0 then mode = MODE_MATH_TEST : kFlag = 1
if inkey$() = "2" and kFlag = 0 then mode = MODE_HISTORY_TEST : kFlag = 1
if inkey$() = "3" and kFlag = 0 then mode = MODE_SCIENCE_TEST : kFlag = 1
if inkey$() = "b" and kFlag = 0 then mode = MODE_TITLE : kFlag = 1
RETURN
MathTest:
rem Display get ready message until user has pressed space bar
if startTest = FALSE
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Get Ready!"
set text size 15
center text 320,260, "Press the space bar to go start"
center text 320,280, "Press B to go back"
if inkey$() = "b" and kFlag = 0 then mode = MODE_TITLE : kFlag = 1
rem user pressed space bar to start the test
if Spacekey() = 1 and kFlag = 0
startTest = TRUE
kFlag = 1
rem reset variables needed for test
gosub ResetTest
endif
else : `Test has started
rem if test is not finished (test is still running)
if finishedTest = FALSE
rem Display test question and possible choices
ink rgb(255,255,255),0 : set text size 30
center text 320,200, math(currentQuestion).question
set text size 15
text 240,280, "A.) " + math(currentQuestion).choice1
text 240,300, "B.) " + math(currentQuestion).choice2
text 240,320, "C.) " + math(currentQuestion).choice3
text 240,340, "D.) " + math(currentQuestion).choice4
rem Read user input
answer = asc(lower$(inkey$())) - 96
rem If user selected a valid choice
if answer > 0 and answer < 5 and kFlag = 0
kFlag = 1
rem if user selected correct answer
if answer = math(currentQuestion).answer
inc gameTime, 5
else : `User selected incorrect answer
dec gameTime, 5
endif
rem move onto the next question
inc currentQuestion
rem if no more questions in this test, mark test as finished
if currentQuestion > array count(math())
finishedTest = TRUE
elapsedTime = (timer() - startingTime) / 1000
remainingTime = gameTime - elapsedTime
endif
endif
else : `Test is finished
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Test Results"
ink rgb(0,255,0),0 : set text size 20
center text 320,280, "Congratulations! You finished the Math test with "+str$(remainingTime)+" seconds left."
ink rgb(255,255,0),0
center text 320,340, "Press any key to continue."
if inkey$() <> "" and kFlag = 0 then mode = MODE_SUBJECT_SELECT : kFlag = 1
endif
endif
RETURN
HistoryTest:
rem Display get ready message until user has pressed space bar
if startTest = FALSE
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Get Ready!"
set text size 15
center text 320,260, "Press the space bar to go start"
center text 320,280, "Press B to go back"
if inkey$() = "b" and kFlag = 0 then mode = MODE_TITLE : kFlag = 1
rem user pressed space bar to start the test
if Spacekey() = 1 and kFlag = 0
startTest = TRUE
kFlag = 1
rem reset variables needed for test
gosub ResetTest
endif
else : `Test has started
rem if test is not finished (test is still running)
if finishedTest = FALSE
rem Display test question and possible choices
ink rgb(255,255,255),0 : set text size 30
center text 320,200, history(currentQuestion).question
set text size 15
text 240,280, "A.) " + history(currentQuestion).choice1
text 240,300, "B.) " + history(currentQuestion).choice2
text 240,320, "C.) " + history(currentQuestion).choice3
text 240,340, "D.) " + history(currentQuestion).choice4
rem Read user input
answer = asc(lower$(inkey$())) - 96
rem If user selected a valid choice
if answer > 0 and answer < 5 and kFlag = 0
kFlag = 1
rem if user selected correct answer
if answer = history(currentQuestion).answer
inc gameTime, 5
else : `User selected incorrect answer
dec gameTime, 5
endif
rem move onto the next question
inc currentQuestion
rem if no more questions in this test, mark test as finished
if currentQuestion > array count(history())
finishedTest = TRUE
elapsedTime = (timer() - startingTime) / 1000
remainingTime = gameTime - elapsedTime
endif
endif
else : `Test is finished
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Test Results"
ink rgb(0,255,0),0 : set text size 20
center text 320,280, "Congratulations! You finished the History test with "+str$(remainingTime)+" seconds left."
ink rgb(255,255,0),0
center text 320,340, "Press any key to continue."
if inkey$() <> "" and kFlag = 0 then mode = MODE_SUBJECT_SELECT : kFlag = 1
endif
endif
RETURN
ScienceTest:
rem Display get ready message until user has pressed space bar
if startTest = FALSE
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Get Ready!"
set text size 15
center text 320,260, "Press the space bar to go start"
center text 320,280, "Press B to go back"
if inkey$() = "b" and kFlag = 0 then mode = MODE_TITLE : kFlag = 1
rem user pressed space bar to start the test
if Spacekey() = 1 and kFlag = 0
startTest = TRUE
kFlag = 1
rem reset variables needed for test
gosub ResetTest
endif
else : `Test has started
rem if test is not finished (test is still running)
if finishedTest = FALSE
rem Display test question and possible choices
ink rgb(255,255,255),0 : set text size 30
center text 320,200, science(currentQuestion).question
set text size 15
text 240,280, "A.) " + science(currentQuestion).choice1
text 240,300, "B.) " + science(currentQuestion).choice2
text 240,320, "C.) " + science(currentQuestion).choice3
text 240,340, "D.) " + science(currentQuestion).choice4
rem Read user input
answer = asc(lower$(inkey$())) - 96
rem If user selected a valid choice
if answer > 0 and answer < 5 and kFlag = 0
kFlag = 1
rem if user selected correct answer
if answer = science(currentQuestion).answer
inc gameTime, 5
else : `User selected incorrect answer
dec gameTime, 5
endif
rem move onto the next question
inc currentQuestion
rem if no more questions in this test, mark test as finished
if currentQuestion > array count(science())
finishedTest = TRUE
elapsedTime = (timer() - startingTime) / 1000
remainingTime = gameTime - elapsedTime
endif
endif
else : `Test is finished
ink rgb(255,255,255),0 : set text size 30
center text 320,200, "Test Results"
ink rgb(0,255,0),0 : set text size 20
center text 320,280, "Congratulations! You finished the Science test with "+str$(remainingTime)+" seconds left."
ink rgb(255,255,0),0
center text 320,340, "Press any key to continue."
if inkey$() <> "" and kFlag = 0 then mode = MODE_SUBJECT_SELECT : kFlag = 1
endif
endif
RETURN
ResetTest:
rem start test with question 1
currentQuestion = 1
rem start test with 15 seconds
gameTime = 15
rem record when test started
startingTime = timer()
rem mark test as unfinished
finishedTest = FALSE
RETURN
MathQuestions:
data 5
data "What is 10+45?", "22", "11", "33", "55", 4
data "What is 30x5?", "50", "60", "150", "98", 3
data "What is 56.1 + 82.3?", "138.4", "125.4", "116.2", "118.4", 1
data "What is 50 - 35 ?", "117", "104.3", "15", "89", 3
data "What is 116x2?", "201", "232", "190", "212", 2
HistoryQuestions:
data 3
data "Who is the second president of the United States?", "Theodore Rosevelt", "John Adams", "George Washington", "Andrew Jackson", 2
data "What was the first war in the United States?", "The War of 1812", "The Indian American War", "The Revolutionary War", "World War II", 3
data "Where did the gold rush take place?", "Boston", "New York City", "Los Angeles", "San Fransisco", 1
ScienceQuestions:
data 1
data "What is the smallest thing on Earth?", "molecule", "atom", "piece of dust", "protons", 2
There are different timers so its hard to put the timer in a code snippet. But thank you for your help.