Why are goto and dofile, among other lua commands, disable
-
- Posts: 1
- Joined: Thu Oct 01, 2015 7:50 pm
Why are goto and dofile, among other lua commands, disabled?
The lua programming language includes the commands 'dofile' and 'goto' among others, and I would like to utilize them with my mods. There is a wonderful debugging utility I would love to use, however, because you don't allow dofile, I can't. I am able, using functions, to work around the goto to a certain extent, however, there is no workaround for the dofile command.
Re: Why are goto and dofile, among other lua commands, disab
In Grimrock 1 you can spawn a script entity and set its source using the SetSource() method. You don't really get dofile functionality but you can get fairly close. Take a look at jkos' LoG Framework.
In Grimrock 2, you can imitate dofile (or dostring) like this:
1. Add this object definition:
2. Add a script_entity called fileDoerControl with this function:
Now you can call fileDoerControl.script.dofile("cows","mod_assets/scripts/cows.lua") to create an object named "cows" with a ScriptComponent named "script" that immediately executes cows.lua. It will support connectors too because it has a ScriptControllerComponent, though of course these connectors will have to be added dynamically.
If you want dostring instead then just replace the loadFile() call with setSource().
As for 'goto', why the hell do you want goto in the first place...
As for other lua features, security.
In Grimrock 2, you can imitate dofile (or dostring) like this:
1. Add this object definition:
Code: Select all
defineObject{
name = "file_doer",
components = {
{
class = "ScriptController",
name = "controller",
onInit = function(self)
self.go.script:loadFile(fileDoerControl.script.filename)
end,
},
{
class = "Script",
},
},
placement = "floor",
}
Code: Select all
function dofile(scriptName,fName)
filename = fName
spawn("file_doer",self.go.level,self.go.x,self.go.y,self.go.facing,self.go.elevation,scriptName)
end
If you want dostring instead then just replace the loadFile() call with setSource().
As for 'goto', why the hell do you want goto in the first place...
As for other lua features, security.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Why are goto and dofile, among other lua commands, disab
Lua 5.1 which Grimrock uses has no goto statement. Goto appeared in Lua 5.2.
Dofile does not work with published mods (all the files are packed in one big file). But you can use "import" in asset definition scripts.
Dofile does not work with published mods (all the files are packed in one big file). But you can use "import" in asset definition scripts.