My file player.lua won't include itself in main.lua.
What did I do wrong.
The .love file is inlcuded below.
*Ugh" How to include lua files
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
*Ugh" How to include lua files
- Attachments
-
- files.love
- (85.99 KiB) Downloaded 136 times
Re: *Ugh" How to include lua files
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.
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.
Re: *Ugh" How to include lua files
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
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.
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.
Code: Select all
local Player = {}
function player.load(self, ...)
--etc
end
return Player
--in main.lua or whatever
local player = require "Player"
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests