Hey guys, I'm making a scene-based game and each scene will be a file in the 'scripts' folder.
I've already do it in ruby, but I have no idea on how to do that in Lua.
Anyone know how to?
Thanks for the attention.
Last edited by wesleylucas on Fri May 10, 2013 12:12 pm, edited 1 time in total.
def or function doesn't matter, you understand what I mean anyway.
So it would be easier if you at least put an example of your code as a reference, but I think I know what you want.
In your main.lua put require "NAME_OF_FOLDER/NAME_OF_FILE"
Don't actually put NAME_OF_FOLDER and whatever. I think you know what I mean.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
You could use love.filesystem.enumerate to get the names of all files in the folder as strings, then use a for loop to iterate over the keys and values in the list that returns (see the example in the docs), and then use each string as an argument to require each file, I think.
require 'require' -- or require 'lib.require', depending on where you put it
local d = require.tree('path.to.directory')
d.file1 -- contents returned by path/to/directory/file1.lua
d.file2 -- contents returned by path/to/directory/file2.lua
d.subdir.file3 -- contents returned by path/to/directory/subdir/file3.lua
require 'require' -- or require 'lib.require', depending on where you put it
local d = require.tree('path.to.directory')
d.file1 -- contents returned by path/to/directory/file1.lua
d.file2 -- contents returned by path/to/directory/file2.lua
d.subdir.file3 -- contents returned by path/to/directory/subdir/file3.lua
Been searching around for this functionality. I downloaded kikito's require.lua and put it in my game base directory. However, I'm having problems trying to get it to work properly.
I currently have a /characters/ (off my base game directory) that has a bunch of files I want to include. What is the proper syntax to include files from another directory? What is the proper syntax to include just 1 file from another directory?
Thanks so much!
Note: I have read the examples above and I'm still having trouble (I'm new to all this!).