How to connect the 2 lua files?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
plz_m0ve
Prole
Posts: 16
Joined: Fri Jan 04, 2013 4:07 pm

How to connect the 2 lua files?

Post by plz_m0ve »

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
LÖVE IS IN THE AIR
- OBEY
User avatar
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: How to connect the 2 lua files?

Post by master both »

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 :)
User avatar
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?

Post by Kjell Granlund »

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
User avatar
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?

Post by bartbes »

I should note that the proper directory separator for require is a ., not /.
User avatar
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?

Post by Kjell Granlund »

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
User avatar
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?

Post by kikito »

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
It works, but by coincidence. It's not guaranteed to work in the future, so you might as well change to "." today.
When I write def I mean function.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to connect the 2 lua files?

Post by Boolsheet »

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.
Shallow indentations.
plz_m0ve
Prole
Posts: 16
Joined: Fri Jan 04, 2013 4:07 pm

Re: How to connect the 2 lua files?

Post by plz_m0ve »

Now im a little confused.

So i write this

Code: Select all

function love.load(require player.lua)
Got a little confused with all the different advanced talk you guys did there. :crazy:
But thanks for the answers :-)
LÖVE IS IN THE AIR
- OBEY
User avatar
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?

Post by Kjell Granlund »

Do not add the extension. Just "player" not "play.lua"
plz_m0ve
Prole
Posts: 16
Joined: Fri Jan 04, 2013 4:07 pm

Re: How to connect the 2 lua files?

Post by plz_m0ve »

Ok, thanks for the answer :-)
LÖVE IS IN THE AIR
- OBEY
Post Reply

Who is online

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