*Ugh" How to include lua files

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
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

*Ugh" How to include lua files

Post by Biphe »

My file player.lua won't include itself in main.lua.
What did I do wrong.
The .love file is inlcuded below.
Attachments
files.love
(85.99 KiB) Downloaded 130 times
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: *Ugh" How to include lua files

Post 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)
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Re: *Ugh" How to include lua files

Post 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.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: *Ugh" How to include lua files

Post 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.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 206 guests