I know its a dumb question but I've been looking it up and don't understand how to do this
I've tried
love.filesystem.load("button.lua()")
love.filesystem.load("button.lua")
love.filesystem.load("button.lua"())
love.filesystem.load(button.lua)
love.filesystem.load("class.lua")
etcetera
--=====
In a folder, I have three lua files: main.lua, button.lua, class.lua
I run it by dragging and dropping on Love2d. I don't really know what I'm supposed to do.
how do I load lua files?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: how do I load lua files?
That should work and return a chunk you can execute:
Code: Select all
local button, errmsg = love.filesystem.load("button.lua")
assert(button, errmsg) -- prints error message if an error occured
button() -- execute the lua file
Code: Select all
-- load button.lua from the current folder, execute it and assign the result to button
local button = require("button")
Last edited by grump on Mon Oct 16, 2017 2:23 am, edited 1 time in total.
- zorg
- Party member
- Posts: 3444
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: how do I load lua files?
Have you read the wiki page on [wikilove.filesystem.load[/wiki] yet? It clearly explains everything.
Also, you don't need to use that if you don't want to, you can always just require in files:
Do note that you need to use dots in require, and you need to not write the file extension.
But if you do want to use l.fs.load, then:
is the quickest solution, though it's not the safest method; the wiki page explains it in more detail.
(Also curse you grump, if there hadn't been a keyboard shortcut that logged me out, my post would have been the first : P)
Also, you don't need to use that if you don't want to, you can always just require in files:
Code: Select all
local someModule = require(path.to.somemodulewithoutextension)
-- or if it contains globals only, though it's bad practice:
require(someothermodulewithoutextension)
But if you do want to use l.fs.load, then:
Code: Select all
local Button = love.filesystem.load('button.lua')()
(Also curse you grump, if there hadn't been a keyboard shortcut that logged me out, my post would have been the first : P)
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: how do I load lua files?
Thx guys it works now ps I did check the wiki, I am just extraordinarily bad at understanding documentation
-
- Prole
- Posts: 15
- Joined: Tue Oct 17, 2017 11:26 pm
Re: how do I load lua files?
use require not loadfile
Who is online
Users browsing this forum: No registered users and 220 guests