I'm new to LOVE lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Jeff Xu
Prole
Posts: 1
Joined: Wed Nov 13, 2013 12:46 am

I'm new to LOVE lua

Post by Jeff Xu »

Hi, I'm new to LOVE 2D's lua... I have previous experience with some LUA, but I'm not sure how to do somethings.
Is there a wait() statement? or a way to delay something?
Thanks
(:
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: I'm new to LOVE lua

Post by DaedalusYoung »

Well, there is love.timer.sleep(), but it's not recommended to use that, as it actually halts the entire program.

The common way of waiting is done by using states and a counter variable. Increase the counter every frame by dt until it reaches a certain value.

Example code:

Code: Select all

love.load()
    timer = 0
    state = "wait"
end

love.update(dt)
    if state == "wait" then
        timer = timer + dt
        if timer >= 5 then -- after 5 seconds
            state = "continue" -- the game state is changed
        end
    end
end

love.draw()
    if state == "wait" then
        love.graphics.print("Not doing anything...", 64, 64) -- this message shows for the first 5 seconds
    elseif state == "continue" then
        love.graphics.print("Going to the next game state.", 64, 64) -- this message shows after that, until you quit LOVE
    end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests