Hello all,
I'm new to Love, and indeed programming in general. Just got into things last weekend as I'm wanting to learn Lua to help with future job applications etc (I'm an industry-experienced level designer).
I'm right at the start of making a basic side-scrolling shooter as my first project. It's coming along alright, but now and again I come up with these little questions that I need answers to, and I figured instead of starting threads for each of them, I'd post them all here. Here's my first question, and thanks in advance:
Q. Instead of keeping all my code in my main.lua file, what code do I use to refer to another file that I want to include (PHP style)?
My ongoing newbie questions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: My ongoing newbie questions
love.filesystem.include or love.filesystem.require will do the trick.
Re: My ongoing newbie questions
Yep it did - project is now neatly arranged into folders, and the code nicely categorised. Cheers
Q. How do I keep track of time in Lua?
(e.g. When player presses this button, do this, then after 2 seconds, stop)
Q. How do I keep track of time in Lua?
(e.g. When player presses this button, do this, then after 2 seconds, stop)
Re: My ongoing newbie questions
love.timer.getTime()
will return the number of seconds your computer has been on since startup.
so if wan't something to happen in two seconds your looking for
love.timer.getTime() + 2
simply store that in a variable
nextaction = love.timer.getTime() + 2
then have a if statement such as
if nextaction and love.timer.getTime() > nextaction then
do this
end
will return the number of seconds your computer has been on since startup.
so if wan't something to happen in two seconds your looking for
love.timer.getTime() + 2
simply store that in a variable
nextaction = love.timer.getTime() + 2
then have a if statement such as
if nextaction and love.timer.getTime() > nextaction then
do this
end
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
Or something that a lot of us do, create a timer variable, and add dt to it every time you are in update, example:
Code: Select all
function load()
--something
timer = 0
--some more
end
function update(dt)
timer = timer + dt
if timer >= 2 then
--do stuff
end
end
Re: My ongoing newbie questions
That second approach looks simpler and neater to me - will try it tonight. Cheers
Q. How would I make a some title screens to click through before the game starts?
I don't currently understand how to delay all the gamey stuff from happening whilst say, displaying a picture for a title screen...
Q. How would I make a some title screens to click through before the game starts?
I don't currently understand how to delay all the gamey stuff from happening whilst say, displaying a picture for a title screen...
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
You can make a global variable that keeps track of the "state" of the game:
Whenever you want to start with the game, just do state='game'. This can easily be extended to include, for example in-game menu's.
Code: Select all
function load()
state = 'title'
--load stuff here
end
-- rest of the game here
function draw()
if state=='title' then
-- display title
elseif state=='game' then
-- display game stuff
end
end
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
The specific question was stopping game logic, which is just the same, but for the update function as well, another (similar) solution is:
(possible for other callbacks as well, of course)
Code: Select all
menu = {}
function menu:update(dt)
--my update stuff for the menu
end
function menu:draw()
--my draw stuff for the menu
end
game = {}
function game:update(dt)
--I guess, you should know the rest...
function load()
curstate = menu
end
function update(dt)
curstate:update(dt)
end
function draw()
curstate:draw()
end
Re: My ongoing newbie questions
I've just implemented a title screen according to Robin's suggestion - cheers Robin
Bartbes - can you briefly describe what your solution is, does, and how it works, etc.?
Bartbes - can you briefly describe what your solution is, does, and how it works, etc.?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
There is a table for every part of the game, in my example they are game and menu, they have their callbacks stashed in that table.
If you want to switch (or init) you assign one of these tables (AKA states) to curstate and call the corresponding callback in the global callbacks.
If this isn't vague...
If you want to switch (or init) you assign one of these tables (AKA states) to curstate and call the corresponding callback in the global callbacks.
If this isn't vague...
Who is online
Users browsing this forum: Google [Bot] and 9 guests