Making an app for computer class. A random number will be generated and the base ten blocks showing how much the. Number is worth show up. My game is working you can test it by changing the sprites but , when it’s the right answer I’ve told it to print yes, and when it’s wrong print no, and if it’s right generate another number to do. After at least one question has been completed, whenever the right answer is on say the second button, it prints yes but it also prints no. I have the actual game with levels and a game over screen, and when you press the right answer it goes to game over even though it still prints yes.
Is there something wrong with my code?
local buttonExample
local buttonExample2
local buttonExample3
level = 1
function setup()
t=60*60
displayMode(FULLSCREEN)
sprite("Dropbox:Generic Button PressedGOOD")
buttonExample = NewButton("Dropbox:generic button copyGOOD","Dropbox:Generic Button PressedGOOD",vec2(800,200))
buttonExample2 = NewButton("Dropbox:generic button copyGOOD","Dropbox:Generic Button PressedGOOD",vec2(800,400))
buttonExample3 = NewButton("Dropbox:generic button copyGOOD","Dropbox:Generic Button PressedGOOD",vec2(800,600))
answer=math.random(10,299)
wrongAnswerOne=math.random(answer-20,answer+20)
wrongAnswerTwo=math.random(answer-20,answer+20)
answerLocation = math.random(1,3)
displayMode(FULLSCREEN)
end
function draw()
t=t-1
if t==0 then
print("you lose")
end
background(57, 203, 34, 255)
local hundredsDivision = answer/100
local hundreds = math.modf(hundredsDivision)
local hundredsRemainder = answer - (hundreds*100)
local tensDivision = hundredsRemainder/10
local tens = math.modf(tensDivision)
local ones = hundredsRemainder - (tens*10)
-- Do your drawing here
-- draw the hundreds
for drawHundreds = 1, hundreds do
sprite("Dropbox:base ten", (0 + drawHundreds*300), 530)
end
-- draw the tens
for drawTens = 1, tens do
sprite("Dropbox:onebyten", (47 + drawTens*70), 270)
end
-- draw the ones
for drawOnes = 1, ones do
sprite("Dropbox:single block", (47 + drawOnes*70), 110)
end
-- This sets a dark background color
fontSize(35)
font("Copperplate-Bold")
fill(0, 0, 0, 255)
if answerLocation == 1 then
text(answer, 900,200)
text(wrongAnswerOne, 900,600)
text(wrongAnswerTwo,900,400)
end
if answerLocation == 2 then
text(answer,900,400)
text(wrongAnswerOne,900,200)
text(wrongAnswerTwo, 900,600)
end
if answerLocation==3 then
text(answer,900,600)
text(wrongAnswerOne,900,400)
text(wrongAnswerTwo,900,200)
end
-- Do your drawing here
buttonExample:draw()
buttonExample2:draw()
buttonExample3:draw()
text("ANSWERS", 890,700)
text("Counter:"..t,WIDTH/2,700)
end
-- This function gets called once every frame
function touched(touch)
-- Do your drawing here
buttonExample:touched(touch)
buttonExample2:touched(touch)
buttonExample3:touched(touch)
if answerLocation==1 then
if(buttonExample.selected == true) then
print("yes!!")
answer=math.random(10,299)
answerLocation=math.random(1,3)
end
if(buttonExample2.selected==true) then
print("No")
end
if (buttonExample3.selected==true) then
print("No")
end
end
if answerLocation==3 then
if(buttonExample3.selected == true) then
print("Yes")
answer=math.random(10,299)
answerLocation = math.random(1,3)
end
if(buttonExample.selected==true)then
print("no")
end
if(buttonExample2.selected==true)then
print("no")
end
end
if answerLocation==2 then
if(buttonExample2.selected==true)then
print("yes")
answer = math.random(10,299)
answerLocation=math.random(1,3)
end
if(buttonExample3.selected==true)then
print("no")
end
if(buttonExample.selected==true)then
print("no")
end
end
end
I used a button class my teacher made, I’ll post it as a second post.