 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
PsyOps
Joined: 23 Jan 2007 Posts: 5
|
Posted: Tue Jan 23, 2007 1:03 pm Post subject: Noob - Timer Question |
|
|
Been teaching myself how to code in Java, then i got sidetracked with Lua.
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: |
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
|
I am very new to coding. Being able to make games for my sons psp has peaked my interest.
any help would be appreciated. _________________ Snoochie Boochies |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Wed Jan 24, 2007 1:50 am Post subject: |
|
|
| Code: |
-- Init it up here somewhere
self.Timer = os.clock(),
-- more code WHiletrue and such
local CHECK_TIME = os.clock() - self.Timer
if (CHECK_TIME >= 1) then
self.Timer = os.clock() -- resets the clock
-- Do stuff here!
end
|
|
|
| Back to top |
|
 |
PsyOps
Joined: 23 Jan 2007 Posts: 5
|
Posted: Wed Jan 24, 2007 11:59 am Post subject: |
|
|
thats exactly what i did, and it works. thnx
ive run into a small snag though. I think it recycles back to 0 after a certain amount of time. so when i try to subtract from local time, it already recycled to 0.
or something like that.
i just need to figure out when it goes back to 0. I think its 5000 seconds or so. _________________ Snoochie Boochies |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Thu Jan 25, 2007 10:34 am Post subject: |
|
|
self.Timer = os.clock() -- resets the clock
If you dont want to reset the clock then dont call that function. Everything should work fine after that |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|