No, it's just that you can keep track of your dependencies much more easily that way.Bindie wrote:So when assigning files and libraries to local variables the do not depend on each other in the same way?
Questions about require, calling tables from files.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Questions about require, calling tables from files.
Help us help you: attach a .love.
Re: Questions about require, calling tables from files.
Alright, so It's more clear.
When assigning functions to local variables using the same approach as:
Can this be done in some way?
Right now I have:
Instead of:
-- Main file
How do I go about this?
When assigning functions to local variables using the same approach as:
Code: Select all
-- Player file:
player = {}
return player
Code: Select all
-- Main file
local player = require 'player'
Right now I have:
Code: Select all
-- Map generation
function mapGen(t)
-- Make map and return t
end
-- Main file
Code: Select all
require 'mapGen'
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Questions about require, calling tables from files.
First, don't forget to do this:
(Note the "local".)
Second, I'm not exactly sure, but I think you want something like this:
Or if your module only needs a single function, you could choose to do something like:
Code: Select all
-- Player file:
local player = {}
return player
Second, I'm not exactly sure, but I think you want something like this:
Code: Select all
--map.lua
local map = {}
function map.generate(t)
-- Make map and return t
end
return map
Code: Select all
--some other module
loca map = require 'map'
...
... = map.generate(...)
Code: Select all
--mapGen.lua
local function mapGen(t)
-- Make map and return t
end
return mapGen
Code: Select all
--some other module
loca mapGen = require 'mapGen'
...
... = mapGen(...)
Help us help you: attach a .love.
Re: Questions about require, calling tables from files.
That's cool. I can return functions as well. I'll add a local to the external files. Awesome.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests