Hi,
Is there a command for how to 'blend' 2 lua files together? I have a main.lua with some stuff and the player code. But how do i like 'connect' them?
I tried with this comment dofile "player.lua", but i just get an error : "Can't find player.lua"... But it is in the same folder?
Someone please help! ;S
How to connect the 2 lua files?
How to connect the 2 lua files?
LÖVE IS IN THE AIR
- OBEY
- OBEY
- master both
- Party member
- Posts: 262
- Joined: Tue Nov 08, 2011 12:39 am
- Location: Chile
Re: How to connect the 2 lua files?
Well... you can use the require funtion.
it loads that lua file into you main file.
example:
require "player"
It load the player.lua file that should be in the same folder as main.lua.
also its recommended to write it at the start of the main.lua file.
i hope this help you, also sorry for my bad english
it loads that lua file into you main file.
example:
require "player"
It load the player.lua file that should be in the same folder as main.lua.
also its recommended to write it at the start of the main.lua file.
i hope this help you, also sorry for my bad english
- Kjell Granlund
- Prole
- Posts: 33
- Joined: Tue Jan 08, 2013 12:39 am
- Location: Virginia Beach, VA USA
Re: How to connect the 2 lua files?
With the require function it can be in a different folder too. I do this alot in my code like this: require("playercode/player") where playercode is the folder and player is the player.lua that has your code in it. Put the require in your main in the load fuction: load() require("playercode/player") end. I hope this helps. Sorry for not using the insert code. My phone is not allowing me to do that. Good luck
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How to connect the 2 lua files?
I should note that the proper directory separator for require is a ., not /.
- Kjell Granlund
- Prole
- Posts: 33
- Joined: Tue Jan 08, 2013 12:39 am
- Location: Virginia Beach, VA USA
Re: How to connect the 2 lua files?
Ah thanks for that bit bartbes. Now when you say proper does that mean "/" still works? I only ask bc I have been using that. And why "." Is there a certain reason for this? Im still very new and want to understand the logic
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: How to connect the 2 lua files?
It works, but by coincidence. It's not guaranteed to work in the future, so you might as well change to "." today.Kjell Granlund wrote:Ah thanks for that bit bartbes. Now when you say proper does that mean "/" still works? I only ask bc I have been using that. And why "." Is there a certain reason for this? Im still very new and want to understand the logic
When I write def I mean function.
Re: How to connect the 2 lua files?
I would call it implementation specific behaviour. It works because Lua passes the unmodified string to the loader which will use a platform specific function. All modern operating systems recognize forward slashes as directory separators. Still, there's no rule that requires them to do so and Lua, being ultra portable, has to account for that. Windows officially uses backslashes and I think Mac OS used to have colons. The syntax with the period creates an interface that should work the same over all platforms. Behind the scene, it just replaces the period with the appropriate directory separator.
There's even more to it once you start loading C modules.
There's even more to it once you start loading C modules.
Shallow indentations.
Re: How to connect the 2 lua files?
Now im a little confused.
So i write this
Got a little confused with all the different advanced talk you guys did there.
But thanks for the answers :-)
So i write this
Code: Select all
function love.load(require player.lua)
But thanks for the answers :-)
LÖVE IS IN THE AIR
- OBEY
- OBEY
- Kjell Granlund
- Prole
- Posts: 33
- Joined: Tue Jan 08, 2013 12:39 am
- Location: Virginia Beach, VA USA
Re: How to connect the 2 lua files?
Do not add the extension. Just "player" not "play.lua"
Who is online
Users browsing this forum: No registered users and 5 guests