I am wondering if anyone knows how to check for this via scripts. I have heard that minmay may know. Hopefully he can respond in his usual fast way!
I need to know this now so that I can call setMaterial() again on any objects that need it after reload.
Does anyone know a way to detect reloading of a saved game?
- Zo Kath Ra
- Posts: 944
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Does anyone know a way to detect reloading of a saved ga
Every component has an onInit(self) function.
AFAIK it only gets called once, when you load a new game.
AFAIK it only gets called once, when you load a new game.
Re: Does anyone know a way to detect reloading of a saved ga
Yes, its only called once, when you start a new game, not reload one. So it does not solve my problem.Zo Kath Ra wrote:Every component has an onInit(self) function.
AFAIK it only gets called once, when you load a new game.
Re: Does anyone know a way to detect reloading of a saved ga
Easiest way in Grimrock 2: minimalSaveState objects are respawned every time the game is reloaded, so they, along with their components, will return to their initial state every time the game is reloaded, which means their onInit hooks will be run again. So you'd just place one object like this one on any map:
Easiest way in Grimrock 1: The "fx" object is never saved. Spawn an "fx" object with a known id and parameters that will keep it alive (like a particle system with infinite emission time) and check for its existence every frame. If it doesn't exist on a frame, then that means the game was just loaded, and you can respawn it and run your on-reload code.
Harder, inferior way (in both games): Abuse the fact that functions are serialized with an environment of the first object encountered with a reference to them, as covered in this thread. The bizarre (yet popular among lazy programmers) Lua construct "function(a) return function() --[do something with a] end end" can probably be used as well.
Code: Select all
defineObject{
name = "reload_detector",
placement = "floor",
minimalSaveState = true,
components = {
{
class = "Null",
onInit = function(self) -- whenever this onInit hook executes, it means the game was started or loaded
reloadScript.script.onReload()
end,
},
},
editorIcon = 1,
}Harder, inferior way (in both games): Abuse the fact that functions are serialized with an environment of the first object encountered with a reference to them, as covered in this thread. The bizarre (yet popular among lazy programmers) Lua construct "function(a) return function() --[do something with a] end end" can probably be used as well.
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: Does anyone know a way to detect reloading of a saved ga
Wow, that is easy. This stuff is all I need to move forward. Thanks!minmay wrote:Easiest way in Grimrock 2: minimalSaveState objects are respawned every time the game is reloaded, so they, along with their components, will return to their initial state every time the game is reloaded, which means their onInit hooks will be run again. So you'd just place one object like this one on any map:Easiest way in Grimrock 1: The "fx" object is never saved. Spawn an "fx" object with a known id and parameters that will keep it alive (like a particle system with infinite emission time) and check for its existence every frame. If it doesn't exist on a frame, then that means the game was just loaded, and you can respawn it and run your on-reload code.Code: Select all
defineObject{ name = "reload_detector", placement = "floor", minimalSaveState = true, components = { { class = "Null", onInit = function(self) -- whenever this onInit hook executes, it means the game was started or loaded reloadScript.script.onReload() end, }, }, editorIcon = 1, }
Harder, inferior way (in both games): Abuse the fact that functions are serialized with an environment of the first object encountered with a reference to them, as covered in this thread. The bizarre (yet popular among lazy programmers) Lua construct "function(a) return function() --[do something with a] end end" can probably be used as well.