Or you take the second draw from main.lua, which would seem a logical thing to do.
However, you posed the question why you should use first.lua, well honoustly, I don't know. If you want to use those as levels, it is possible to just use a lua file that defines a load of variables, which you then execute with the 'engine' (which is main.lua in my example).
Can you make a game load another lua file
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- keyspinner
- Prole
- Posts: 24
- Joined: Mon Sep 01, 2008 12:03 am
Re: Can you make a game load another lua file
Well I was mainly trying to do this to not confuse myself, because I do this all the time, for example in math class I write too much and can't find anything.
I am going to need you fix my code so I can see how it's supposed to look, if you know how.
Because I suck at understanding anything for some reason.
I am going to need you fix my code so I can see how it's supposed to look, if you know how.
Because I suck at understanding anything for some reason.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Can you make a game load another lua file
main.lua:
First.lua:
It should work now, only difference is a removed 2nd draw in main.lua, and fixed a tiny bug.
Code: Select all
function load()
font = love.graphics.newFont(love.default_font, 12)
love.graphics.setFont(font)
title = "lua demo"
play = "press space to play"
end
function draw()
love.graphics.draw(title, 50, 50)
love.graphics.draw(play, 400, 300)
end
function keyreleased(key)
if key == love.key_space then
love.filesystem.require(first.lua)
load()
end
end
First.lua:
Code: Select all
function load()
font = love.graphics.newFont(love.default_font, 12)
love.graphics.setFont(font)
message = "Level 1"
end
function draw()
love.graphics.draw(message, 400, 300)
end
- keyspinner
- Prole
- Posts: 24
- Joined: Mon Sep 01, 2008 12:03 am
Re: Can you make a game load another lua file
Oh, thanks I see what you did!
I'm so blind, I should have realized there should be only 1 draw function.
Thank you.
I'm so blind, I should have realized there should be only 1 draw function.
Thank you.
Last edited by keyspinner on Mon Sep 01, 2008 8:06 pm, edited 2 times in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Can you make a game load another lua file
As you can see in my first few posts, everyone makes mistakes.
If you need any more help, don't be afraid to ask, that's what these forums are for.
If you need any more help, don't be afraid to ask, that's what these forums are for.
- keyspinner
- Prole
- Posts: 24
- Joined: Mon Sep 01, 2008 12:03 am
Re: Can you make a game load another lua file
Now I'm getting a runtime error
Stack traceback:
line 15 in main.lua for function in line 13
it tells me 'first' is a 'nil' value
Stack traceback:
line 15 in main.lua for function in line 13
it tells me 'first' is a 'nil' value
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Can you make a game load another lua file
Yeah, missed that one, first.lua should have quotation marks around it as it's a string not a variable, so it should be
Code: Select all
love.filesystem.require("first.lua")
- keyspinner
- Prole
- Posts: 24
- Joined: Mon Sep 01, 2008 12:03 am
Re: Can you make a game load another lua file
Thanks man, I'm just learning something new every minute,
let's hope this works.
Success! Thanks!
let's hope this works.
Success! Thanks!
Who is online
Users browsing this forum: Bing [Bot] and 1 guest