Page 1 of 1

advanced lua scripting

Posted: Mon Nov 27, 2017 6:21 am
by Anakin
Hey,

i'm looking forward to do some scripting, but i'm not 100% sure how to do so, or if this is even possible.
So what i need ist:
1) browsing directories and get folder names,
2) string manipulation,
3) check if a file exist,
4) load that file if it does exist.

specialy for 1) and 2) i'm not sure how to do so

Re: advanced lua scripting

Posted: Mon Nov 27, 2017 1:52 pm
by Marth8880
Anakin wrote:1) browsing directories and get folder names,
Unfortunately Lua doesn't come with any file system libraries, and SWBF2's Lua implementation lacks the I/O library (among others).
Anakin wrote:2) string manipulation,
What specifically are you trying to do with strings? See here: https://www.lua.org/pil/20.html
Anakin wrote:3) check if a file exist,
4) load that file if it does exist.
See `ScriptCB_IsFileExist(filePath)`, which returns true if a file at the specified path exists, or nil if not. As for loading the file, you'd obviously want `ReadDataFile(lvlFilePath)` or `ScriptCB_DoFile(scriptFilePath)` depending on the file type.

Re: advanced lua scripting

Posted: Mon Nov 27, 2017 5:41 pm
by Anakin
to avoid the user and GC script conflicts I thought of an user and GC script that search in all subfolders from the addon folder for a special file and load it.

Let's say this way:
addon\XXX\scripts\xxx_scripts.lvl (GC script)
Addon\xxx\scripts\xxx_ingame.lvl (userscript)

So I need to get a list of folder names (xxx) and manipulate a string to build the total path where I wanna search for the file and (if it exist) load it

Re: advanced lua scripting

Posted: Mon Nov 27, 2017 5:55 pm
by Marth8880
Anakin wrote:So I need to get a list of folder names (xxx) and manipulate a string to build the total path where I wanna search for the file and (if it exist) load it
Unfortunately you can't.

However, I wrote a batch script for MEU that installs user scripts/GCs by looking through existing ones by name and installing it in the first available "slot". The script is here: https://www.dropbox.com/s/h6dup8qht2wxz ... s.zip?dl=0

To use it, you just pass an argument to the script with a value of either `custom_gc` or `user_script`. You'll also need to edit BIN_DIR, USERSCRIPTS_DIR, and TEMP_DIR to reflect your own project.