This is some code i wrote but i cant get it to do what i want.
this is a noob slot machine in the making. This code wont be used like this, its just for me to get an understanding of how lua works. Later i will implement the code in as its needed. Right now I am trying to make square activate the first slot. But i want it to pause randomly between 1-5 seconds. I cant get the timer to work, I'm sure its cause im an idiot and am not understanding something.
Code: Select all
red = Color.new(255,0,0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
white = Color.new(255, 255, 255)
dofile("animLib.lua")
test = SS.new("reel2", "png", 96, 96, "images/")
slot1 = 0
slot2 = 0
slot3 = 0
while true do --begins main body
pad = Controls.read()
if pad:start() then break end
if slot1 == 0 then test:blit(72, 88, 25) end
if slot2 == 0 then test:blit(192, 88, 25) end
if slot3 == 0 then test:blit(312, 88, 25) end
screen:print(0, 0, "Slot1 = "..slot1.." Slot2 = "..slot2.." Slot3 = "..slot3, blue)
if pad:square() then
pullTimer()
end -- end pad:square()
if pad:circle() then
if (slot1 > 0) and (slot2 > 0) and (slot3 > 0) then
slot1 = 0
slot2 = 0
slot3 = 0
end
end -- end pad:circle()
function pullTimer()
timer = Timer.new()
x = math.floor(timer:time()/1000)
screen:print(10,10,x, blue)
t = math.random(5)
if t == x then
activatePull()
timer:reset(0)
end
end -- end pullTimer()
function activatePull()
if slot1 == 0 then
slot1 = pull(0)
else if slot2 == 0 then
slot2 = pull(0)
else if slot3 == 0 then
slot3 = pull(0)
end
end
end
end --end activatePull()
function pull(p)
p = math.random(127)
return p
end -- end pull()
screen.flip()
screen.waitVblankStart()
end --end main body
any help would be appreciated.