So, example:
A person downloads my game then he wants to alter the game's gameplay a little bit then he goes to a folder in where he installed the game which is called something like "Scripts" then he puts a .lua file there then when he runs the game, the .lua script in the "Scripts" folder will be executed.
Will doing that be possible, if so, then how? Thanks in advance
Execute lua script in a user's folder
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Execute lua script in a user's folder
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: Execute lua script in a user's folder
Hi,
first check out the functions in love.filesystem. These allow you to get a list of all files in a certain folder and to run lua-files.
love.filesystem only allows you to look for files in certain places, which is the game folder and the game's save directory. So you have two options: Either tell the user to place his lua-file in the save directory (you can display it with getSaveDirectory) or you distribute the game un-zipped, which means not as a .love file. In the latter case, the user can just put files into the game folder.
first check out the functions in love.filesystem. These allow you to get a list of all files in a certain folder and to run lua-files.
love.filesystem only allows you to look for files in certain places, which is the game folder and the game's save directory. So you have two options: Either tell the user to place his lua-file in the save directory (you can display it with getSaveDirectory) or you distribute the game un-zipped, which means not as a .love file. In the latter case, the user can just put files into the game folder.
Check out my blog on gamedev
Re: Execute lua script in a user's folder
Aw, so there's no way to somehow "create" a directory in the user's folder(where the user puts the game in) ?
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: Execute lua script in a user's folder
If you distribute the game "as is", in form of the source code (instead of packing it into a .love-file), then you can do it.louie999 wrote:Aw, so there's no way to somehow "create" a directory in the user's folder(where the user puts the game in) ?
Check out my blog on gamedev
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Execute lua script in a user's folder
Not with love.filesystem – and even without it, operating systems (including Windows) tend to restrict where programs can write files, so for example programs generally can't write to anywhere in the Program Files folder unless the user explicitly allows it themselves.louie999 wrote:Aw, so there's no way to somehow "create" a directory in the user's folder(where the user puts the game in) ?
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: Execute lua script in a user's folder
Maybe you can use ffi, but it's not recommended. I'm using it (muzz said that Slime wrote it)to set the write dir to wherever I want, using this function . but I don't know if it works to read files. There are ffi PHYSFS functions that cand read files and save it in Strings, but you will need know a little bit of C, (Which is a problem to me, heh). You might can do this, but it won't be easy(But if you do it, share the code, I'm new to that ffi thing, too )
Code: Select all
function changeDirectory()
local ffi = require("ffi")
ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]];
ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]]
local liblove = ffi.os == "Windows" and ffi.load("love") or ffi.C
-- This grabs your source folder, but you can point it anywhere,
--Look at love.filesystem to see what you can call so that you can keep it multiplatform.
local docsdir = love.filesystem.getSourceBaseDirectory()
liblove.PHYSFS_setWriteDir(docsdir)
liblove.PHYSFS_mount(docsdir, nil, 0)
end
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Re: Execute lua script in a user's folder
Yeah as i said in your other thread, i think it's good if you want to make your game install completely portable, but if you are making a game, and not a tool or something else like that i would use Love's intended functionality.
Who is online
Users browsing this forum: K2-XT and 134 guests