I am still new to how scripting in this game works. The question I have is whether there is a starting script that runs where I can add any up-front settings for the game. It seems all scripts must be tied to a connector, which means they are basically triggered. I want one that executes one time when the game starts.
I do see a script called init.lua. It does seem to execute when the map loads into the editor. I know this only because if I type syntax errors the map won't load. However, any global variables I set or anything else I do in there doesn't seem to be accessible inside the script entities you define in the map. I guess they don't seem to be global even though I do declare them outside any function in init.lua.
Is there an "init" or "start" function that the game calls?
-
- Posts: 11
- Joined: Sat Oct 18, 2014 9:14 pm
Re: Is there an "init" or "start" function that the game cal
You can maybe do a floor trigger (they're unseen).
Re: Is there an "init" or "start" function that the game cal
Script entity code is run immediately when the game starts. But if you put your code in a function definition it won't execute until something actually calls the function. So something like:
won't print "stuff" until something calls stuff(). But if you have a script entity that only contains:
outside of any functions, it should print "stuff" immediately. Or if you want to keep your code in a function (you almost certainly do) just do this:
Code: Select all
function stuff()
print("stuff")
end
Code: Select all
print("stuff")
Code: Select all
function stuff()
print("stuff")
end
stuff()
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: Is there an "init" or "start" function that the game cal
Thanks! That works.