Posted 23 January 2014 - 04:13 PM
hello,
I made a simple timer :
I'm making a simple quiz program :
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
time=10
calcmax=20
calc=0
result=0
while true do
shell.run("clear")
x=math.random(1,9)
y=math.random(1,9)
write("Il reste "..calcmax-calc.." calculs score : "..result.."/"..calcmax)
print("")
print("")
calc=calc+1
write(x.."+"..y.."=")
answer=tonumber(read())
z=x+y
if calc==calcmax then
shell.run("clear")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
centerText(result.."/"..calcmax)
if result<calcmax/2 then
print("")
centerText("PERDU")
elseif result>=calcmax/2 then
print("")
centerText("GAGNE")
end
sleep(5)
shell.run("quiz")
end
if answer==quit then
shell.run("quiz")
end
if answer==z then
result=result+1
print("")
print("")
centerText("BRAVO!")
print("")
print("")
centerText("Appuyez sur une touche pour continuer")
os.pullEvent("key")
else
print("")
print("")
centerText("faux")
sleep(0.5)
print("")
print("")
print("la bonne réponse était "..z)
print("")
print("")
centerText("Appuyez sur une touche pour continuer")
os.pullEvent("key")
end
endand I'd love to add a timer for it,the problem is if I add a timer,nothing will work until the timer reach 0
is there a way to make that sleep stop only a part of the program isntead of the whole one?
I made a simple timer :
repeat
time=time-1
sleep(1)
until
time==0
but I can't put it into more advanced programs because the sleep don't stop only the timer,it stop the whole programI'm making a simple quiz program :
Spoiler
local function centerText(text)local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
time=10
calcmax=20
calc=0
result=0
while true do
shell.run("clear")
x=math.random(1,9)
y=math.random(1,9)
write("Il reste "..calcmax-calc.." calculs score : "..result.."/"..calcmax)
print("")
print("")
calc=calc+1
write(x.."+"..y.."=")
answer=tonumber(read())
z=x+y
if calc==calcmax then
shell.run("clear")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
centerText(result.."/"..calcmax)
if result<calcmax/2 then
print("")
centerText("PERDU")
elseif result>=calcmax/2 then
print("")
centerText("GAGNE")
end
sleep(5)
shell.run("quiz")
end
if answer==quit then
shell.run("quiz")
end
if answer==z then
result=result+1
print("")
print("")
centerText("BRAVO!")
print("")
print("")
centerText("Appuyez sur une touche pour continuer")
os.pullEvent("key")
else
print("")
print("")
centerText("faux")
sleep(0.5)
print("")
print("")
print("la bonne réponse était "..z)
print("")
print("")
centerText("Appuyez sur une touche pour continuer")
os.pullEvent("key")
end
end
is there a way to make that sleep stop only a part of the program isntead of the whole one?