Run a different file *solved*
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Run a different file *solved*
In main.lua, how do you run a different .lua file? I need this for a menu screen because I cannot undraw images. I dont think I need to post any code, so any answers?
Last edited by TeeJayz on Tue Aug 14, 2012 8:25 pm, edited 1 time in total.
Re: Run a different file
To load a different file you have to put require "filename" (IMPORTANT: Make sure you put the file NAME, but not the extension. So require "menu" not require "menu.lua".)
Now none of your code is going to be run, unless you call those functions inside of the main love. functions. Here's an example.
This is what your menu.lua could look like
And now here is what your main.lua could look like
And that's all it takes to run stuff from other files.
One more little thing to note. When you have a parameter that you want to use inside one of your functions (For example, dt in menu_update) you must have that parameter written when you call it. So like this
That is fine as long as you call it like this
Now none of your code is going to be run, unless you call those functions inside of the main love. functions. Here's an example.
This is what your menu.lua could look like
Code: Select all
function menu_load()
--Menu loading stuff
end
function menu_draw()
-- Menu drawing stuff
end
function menu_update(dt)
-- Menu updating stuff
end
Code: Select all
require "menu"
function love.load()
menu_load()
-- Other loading stuff
end
function love.draw()
menu_draw()
-- Other drawing stuff
end
function love.update(dt)
menu_update(dt)
-- Other updating stuff
end
One more little thing to note. When you have a parameter that you want to use inside one of your functions (For example, dt in menu_update) you must have that parameter written when you call it. So like this
Code: Select all
function menu_update(dt)
--Dt stuff
end
Code: Select all
function love.update(dt) -- You need to have dt in this as well
menu_update(dt) --See the dt
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Run a different file
You don't need to.TeeJayz wrote:I cannot undraw images
Every frame, the screen is cleared. Every frame, love.update() and love.draw() are run. Use if statements and for loops and so on to decide what should be drawn.
Help us help you: attach a .love.
Re: Run a different file
I dont know how to go forward 1 frame.Robin wrote:You don't need to.TeeJayz wrote:I cannot undraw images
Every frame, the screen is cleared. Every frame, love.update() and love.draw() are run. Use if statements and for loops and so on to decide what should be drawn.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Run a different file
It happens automatically. You don't need to worry about that.
Help us help you: attach a .love.
Who is online
Users browsing this forum: slime and 6 guests