Im not waiting for anything, i want to know how can i wait in my code?
I have seen some versions of Lua have a 'wait()' function. Does Love have one? Incase it does have, i have really doen my code bad.
But anyways, how can i wait?
Ex:
mybool = true
wait(5)
mybool = false
Thanks!
Waiting.
Re: Waiting.
See this page here buddy: http://lua-users.org/wiki/SleepFunction
The author provides this solution:
The os.clock function is explained here: http://www.lua.org/manual/5.1/manual.html#pdf-os.clock
-Akima
The author provides this solution:
Code: Select all
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
-- warning: clock can eventually wrap around for sufficiently large n
-- (whose value is platform dependent). Even for n == 1, clock() - t0
-- might become negative on the second that clock wraps.
-Akima
Re: Waiting.
Okay...
Then is it possibel to wait until a sound has finished playing? Its a static sound.
Then is it possibel to wait until a sound has finished playing? Its a static sound.
I can't come up with a good signature!
Re: Waiting.
Well. You could use the TEsound library: http://love2d.org/wiki/TEsound
That page explains that you play a sound using this function call:
that last parameter func, is a callback function that gets called when the sound finishes playing, so you would make a new function and pass its name as a parameter, like so:
That page explains that you play a sound using this function call:
Code: Select all
TEsound.play(sound, tags, volume, pitch, func)
Code: Select all
function my_func_to_call_when_sound_stops()
-- do stuff here
end
TEsound.play("sounds/jump.ogg", {"action", "player"}, 1, 1, my_func_to_call_when_sound_stops)
Re: Waiting.
love.timer.sleep. But what are you really trying to do?
Re: Waiting.
Im trying to make a virtual weapon. I need to wait reloading.
I can't come up with a good signature!
Re: Waiting.
Then you need a timer, because sleep will stop the execution of the whole game. How that works was explained to you before: Waiting, calling a function and waiting again
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Waiting.
You don't want to sleep here, because that pauses the game completely. What you want is update the variable in another frame. You can do it like this:
Code: Select all
function love.update(dt)
if start_reloading then -- or however you do this
start_reloading = false
reload_wait = 1
mybool = true
end
if reload_wait then
reload_wait = reload_wait - dt
if reload_wait < 0 then
mybool = false
reload_wait = nil
end
end
end
Help us help you: attach a .love.
Re: Waiting.
It took me quite a while to be able to picture in my head how an event loop worked and how that affected my programs. I can see why it might be hard for him to grasp right now.vrld wrote:Then you need a timer, because sleep will stop the execution of the whole game. How that works was explained to you before: Waiting, calling a function and waiting again
Re: Waiting.
This busy loop will kill your CPU. If you really want to pause the code execution, you could use socket.sleep().akima wrote:See this page here buddy: http://lua-users.org/wiki/SleepFunction
The author provides this solution:The os.clock function is explained here: http://www.lua.org/manual/5.1/manual.html#pdf-os.clockCode: Select all
local clock = os.clock function sleep(n) -- seconds local t0 = clock() while clock() - t0 <= n do end end -- warning: clock can eventually wrap around for sufficiently large n -- (whose value is platform dependent). Even for n == 1, clock() - t0 -- might become negative on the second that clock wraps.
-Akima
You may use it in plain old lua, but you never should use it in Love - you want your game to be drawn at 60 FPS, and respond to events like keypresses or mouse clicks, right?
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Who is online
Users browsing this forum: Bing [Bot] and 3 guests