Page 1 of 1
*Ugh" How to include lua files
Posted: Mon Dec 23, 2013 4:07 am
by Biphe
My file player.lua won't include itself in main.lua.
What did I do wrong.
The .love file is inlcuded below.
Re: *Ugh" How to include lua files
Posted: Mon Dec 23, 2013 4:27 am
by Lafolie
You created the 'player' table inside of a function that you intended to be an element of said table.
It might be a good idea to have the table created beforehand and implicitly passing a reference of the table using self.
Code: Select all
player = {}
function player.someFunction(self, someArg)
self.x = someArg
self.y = 16
--etc
end
--invoked with semicolon to implicitly pass self as the first arg
player:someFunction(32)
Re: *Ugh" How to include lua files
Posted: Mon Dec 23, 2013 8:58 am
by Biphe
Thanks. I will try that from now on. Also sorry for the mess I was just in the process of transferring code to the player.lua file.
Re: *Ugh" How to include lua files
Posted: Mon Dec 23, 2013 5:19 pm
by Lafolie
I've seen a lot worse, it was fine really. One other thing I would suggest is making the player object a local value that is returned by it's definition file.
Code: Select all
local Player = {}
function player.load(self, ...)
--etc
end
return Player
--in main.lua or whatever
local player = require "Player"
Doing things this way is good practice for when you step up into the realms of OOP which, judging by what you're doing currently, you should have an easy time getting to grips with.