Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 14th Jan 2014 19:09
Hey guys, im trying to make a school quiz game with a timer. The timer works in some ways but it can go to the negatives and the second digit of the timer whites out because the numbers don't disappear. Heres a code snippit:


REM PROJECT
REM SCIENCE PROJECT

autocam off

title:
cls
ink rgb (255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,60, "Welcome Science Mania!"
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"

do
if inkey$()="x" then gosub ModeSelect
if inkey$()="h" then gosub instructions

loop

Instructions:
cls
ink rgb (255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,60, "Instructions"
set text size 15
Center text 320,160, "Welcome to the Science Mania Test Prep! In this Game"
center text 320,180, "you have to answer as many problems as you can"
ink rgb (0,255,0),0
center text 320,400, "Press B to go back."

do
if inkey$()="b" then gosub title
loop

ModeSelect:
cls
ink rgb (255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,200,"Which subject do you want to select?"
set text size 15
text 240,280,"1.)Math"
text 240,300,"2.)English"
text 240,320,"3.)Science"
center text 320,380, "Press B to go back"

do
if inkey$()="1"
do
if inkey$() <> "1" then exit
loop
gosub GetReady1
endif



GetReady1:
cls
ink rgb(255,255,255),0 : set text font "arial": set text size 30 : set text to normal
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"

do
if inkey$()="b" then gosub title
if Spacekey()=1 then gosub Level1
loop



Level1:
cls
ProblemCorrect = 0
AnswersCorrect = 0
Seconds = 15
T=Timer()

rem put bitmap here later
ink rgb(255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,200,"What is 2+2?"
set text size 15
text 240,280, "A.)2"
text 240,300, "B.)1"
text 240,320, "C.)3"
text 240,340, "D.)4"

repeat
Elapsed=(Timer()-T)/1000
TimeLeft=Seconds-Elapsed
Text 20,20,"Seconds Left: "+Str$(TimeLeft)


if inkey$()="b"
do
if inkey$() <> "b" then exit
loop
ProblemCorrect = 2
AnswersCorrect = AnswersCorrect + 1
Seconds = Seconds - 5
gosub Level2
endif
if inkey$()="a"
do
if inkey$() <> "a" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level2
endif
if inkey$()="c"
do
if inkey$() <> "c" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level2
endif
if inkey$()="d"
do
if inkey$() <> "d" then exit
loop
ProblemCorrect = 1
Seconds = Seconds + 5
gosub Level2
endif
if TimeLeft <= 9 then Text 105,20," "
if TimeLeft <= 99 then Text 111,20," "
until TimeLeft = 0

end

Level2:
cls
rem load bitmap here
ink rgb(255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,200, "What is 99+1?"
set text size 15
if ProblemCorrect = 1 then ink rgb(0,255,0),0 : center text 320,150, "CORRECT! +5 SECONDS"
if ProblemCorrect = 2 then ink rgb(255,0,0),0 : center text 320,150, " WRONG! -5 SECONDS"
ink rgb(255,255,255),0
text 240,280,"A.)50"
text 240,300,"B.)60"
text 240,320,"C.)100"
text 240,340,"D.)98"

repeat
Elapsed=(Timer()-T)/1000
TimeLeft=Seconds-Elapsed
Text 20,20,"Seconds Left: "+Str$(TimeLeft)

if inkey$()="b"
do
if inkey$() <> "b" then exit
loop
ProblemCorrect = 2
AnswersCorrect = AnswersCorrect + 1
Seconds = Seconds - 5
gosub Level3
endif
if inkey$()="a"
do
if inkey$() <> "a" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level3
endif
if inkey$()="c"
do
if inkey$() <> "c" then exit
loop
ProblemCorrect = 1
Seconds = Seconds + 5
gosub Level3
endif
if inkey$()="d"
do
if inkey$() <> "d" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level3
endif
if TimeLeft <= 9 then Text 105,20," "
if TimeLeft <= 99 then Text 111,20," "
until TimeLeft = 0

Level3:
cls
rem load bitmap here
ink rgb(255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,200, "What is 56.1+82.3?"
set text size 15
if ProblemCorrect = 1 then ink rgb(0,255,0),0 : center text 320,150, "CORRECT! +5 SECONDS"
if ProblemCorrect = 2 then ink rgb(255,0,0),0 : center text 320,150, " WRONG! -5 SECONDS"
ink rgb(255,255,255),0
text 240,280,"A.)133.4"
text 240,300,"B.)125.4"
text 240,320,"C.)116.2"
text 240,340,"D.)118.4"

repeat
Elapsed=(Timer()-T)/1000
TimeLeft=Seconds-Elapsed
Text 20,20,"Seconds Left: "+Str$(TimeLeft)

if inkey$()="b"
do
if inkey$() <> "b" then exit
loop
ProblemCorrect = 2
AnswersCorrect = AnswersCorrect + 1
Seconds = Seconds + 5
gosub Level3
endif
if inkey$()="a"
do
if inkey$() <> "a" then exit
loop
ProblemCorrect = 1
Seconds = Seconds + 5
gosub Level3
endif
if inkey$()="c"
do
if inkey$() <> "c" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level3
endif
if inkey$()="d"
do
if inkey$() <> "d" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level3
endif
if TimeLeft <= 9 then Text 105,20," "
if TimeLeft <= 99 then Text 111,20," "
until TimeLeft = 0

Level2:
cls
rem load bitmap here
ink rgb(255,255,255),0 : set text font "arial" : set text size 30 : set text to normal
center text 320,200, "What is 216.7 - 117.4?"
set text size 15
if ProblemCorrect = 1 then ink rgb(0,255,0),0 : center text 320,150, "CORRECT! +5 SECONDS"
if ProblemCorrect = 2 then ink rgb(255,0,0),0 : center text 320,150, " WRONG! -5 SECONDS"
ink rgb(255,255,255),0
text 240,280,"A.)117.6"
text 240,300,"B.)104.3"
text 240,320,"C.)99.3"
text 240,340,"D.)89.3"

repeat
Elapsed=(Timer()-T)/1000
TimeLeft=Seconds-Elapsed
Text 20,20,"Seconds Left: "+Str$(TimeLeft)

if inkey$()="b"
do
if inkey$() <> "b" then exit
loop
ProblemCorrect = 2
AnswersCorrect = AnswersCorrect + 1
Seconds = Seconds - 5
gosub Level2
endif
if inkey$()="a"
do
if inkey$() <> "a" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level2
endif
if inkey$()="c"
do
if inkey$() <> "c" then exit
loop
ProblemCorrect = 1
Seconds = Seconds + 5
gosub Level2
endif
if inkey$()="d"
do
if inkey$() <> "d" then exit
loop
ProblemCorrect = 2
Seconds = Seconds - 5
gosub Level2
endif
if TimeLeft <= 9 then Text 105,20," "
if TimeLeft <= 99 then Text 111,20," "
until TimeLeft = 0


loop
end


Here is the timer implemented in the game:

repeat
Elapsed=(Timer()-T)/1000
TimeLeft=Seconds-Elapsed
Text 20,20,"Seconds Left: "+Str$(TimeLeft)
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Jan 2014 13:27
Please use code tags.

Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 15th Jan 2014 16:12
I would rather rewrite your code than to pore over the content of all those repeat statements!

You should consider a READ/DATA format or reading from files for a quiz project like this. Your code could be 10x smaller than this.

D.D.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 15th Jan 2014 17:27
Considering your code, I see a lot of gosubs with no return. May I suggest reading Nickydude’s; Beginners Guide to DBPro and then try it again.
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 15th Jan 2014 19:19
I know that, me and my parthner copied off of a paper our teacher gave us. just give us some help with the timer please and thank you.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 16th Jan 2014 00:42 Edited at: 16th Jan 2014 04:54
I’m in a generous mood today, so here is the code.



And without using sync and the backdrop.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 22nd Jan 2014 18:16
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 22nd Jan 2014 18:16
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 22nd Jan 2014 18:28
hides questions

Login to post a reply

Server time is: 2026-07-06 07:52:07
Your offset time is: 2026-07-06 07:52:07