Why are goto and dofile, among other lua commands, disable

Have trouble running Grimrock 1 or you're wondering if your graphics card is supported? Look for help here.
Post Reply
fdrown2226
Posts: 1
Joined: Thu Oct 01, 2015 7:50 pm

Why are goto and dofile, among other lua commands, disabled?

Post by fdrown2226 »

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. :cry:
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Why are goto and dofile, among other lua commands, disab

Post by minmay »

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:

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",
}
2. Add a script_entity called fileDoerControl with this function:

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
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.
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.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Why are goto and dofile, among other lua commands, disab

Post by petri »

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.
Post Reply