Hi all,
I am new to coding with an engine and I'm currently trying to create a simple game with multiple files. I realise that love.filesystem and require statements should be used to do this, but I cannot for the life of me figure it out. Can somebody end my confusion? How do I link different files together, for example one script that creates a world and one that creates a player and lets him walk around? What are some of the things I can do using love.filesystem?
Thanks,
Xpali2
External files
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: External files
A tut: http://sheepolution.com/learn/book/contents
also more guides: https://love2d.org/wiki/Category:Tutorials
and of couse...use the Löve wiki https://love2d.org/wiki/Main_Page
also more guides: https://love2d.org/wiki/Category:Tutorials
and of couse...use the Löve wiki https://love2d.org/wiki/Main_Page
Re: External files
require is used to load Lua scripts.
love.filesystem works with any kind of file, plain text or whatever.
There is no "linking" as in the way compilers link files.
Everything in Lua is done dynamically, so scripts are loaded and executed as soon as you call "require(somefile)".
But yea, tutorials are a good way to start.
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: External files
require needs a .lua file, and it loads and runs the contents of the file you give it, and either returns true if it was successful, or whatever it found after a return statement in a file. If you create local variables, require won't "comb" those together from multiple files, but you can always return those directly if you want. If you just define variables without the local keyword, those will be visible outside that file, but that is kinda considered bad practice due to loss of locality, and needing to keep in mind what was defined where and not passed explicitly.
kikito had a good writeup on module authoring that somewhat teaches you how require works: http://kiki.to/blog/2014/03/30/a-guide- ... a-modules/
Also, you can use love.filesystem.load if you don't want require to put stuff into the table called package.loaded
kikito had a good writeup on module authoring that somewhat teaches you how require works: http://kiki.to/blog/2014/03/30/a-guide- ... a-modules/
Also, you can use love.filesystem.load if you don't want require to put stuff into the table called package.loaded
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: External files
Thanks for the replies,
Wait so require is actually messy? Is there a better way to do this?
Wait so require is actually messy? Is there a better way to do this?
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: External files
depends on what you mean by "messy". i prefer love.filesystem.load myself.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: External files
Well I would define messy as unoptimised and inefficent. Anyways, I guess I will have to look at both require and love.filesystem.
- zorg
- Party member
- Posts: 3441
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: External files
...But no one said they were unoptimized and inefficient?
I only said that it does some stuff behind the scenes, i.e. does package.loaded[<modulename>] = <the return value of the require call> but that's it.
lua is an interpreted language, can't skirt too much around that; the fact that Löve uses luaJIT to make things way faster doesn't modify the inner workings of the language too much; you still need to parse, and then execute any chunk you load into your program (which require does, and love.filesystem.load does partially, you'll need to run the chunk yourself just like a function with ()-s)... well, you don't HAVE to, but you usually do, if you want to access variables and functions in that scope.
I only said that it does some stuff behind the scenes, i.e. does package.loaded[<modulename>] = <the return value of the require call> but that's it.
lua is an interpreted language, can't skirt too much around that; the fact that Löve uses luaJIT to make things way faster doesn't modify the inner workings of the language too much; you still need to parse, and then execute any chunk you load into your program (which require does, and love.filesystem.load does partially, you'll need to run the chunk yourself just like a function with ()-s)... well, you don't HAVE to, but you usually do, if you want to access variables and functions in that scope.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: External files
I see. Well I think I know what to do now.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 27 guests