Spawner activation issue

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Dewalrus
Posts: 20
Joined: Thu Feb 19, 2015 11:35 pm

Spawner activation issue

Post by Dewalrus »

I have a set of lights that activate from a spawner when a lever is thrown. In the Editor this works just fine, but when I test from an export, one of those lights is already on before the lever is touched. (In case it matters, I'm using the Dummy Light, whose appearance most closely fits my intention.) Any ideas what might be going on?
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Spawner activation issue

Post by Azel »

I can test this out for you later, but at first glance I suspect that it has to do with the Save State. Some objects have a default state and nothing you do can change that once the game is played, saved, and loaded. So, even if you use the Editor to turn off the Lights on a Dummy Light, the moment a player Saves/Loads the game, the Lights stay on (the game does not Save the State of the Dummy Light thus reverts to default settings).

The Tomb Ceiling Lamp seems to stay On and Off after a Save/Load. I use this for one of the puzzles in my Myst Mod and haven't seen any issues yet. So if the problem you describe is related to the Save State of a Dummy Light then you can either Clone the object and set its Save State to "true" or use a different light source, like the Tomb Ceiling Lamp.
Dewalrus
Posts: 20
Joined: Thu Feb 19, 2015 11:35 pm

Re: Spawner activation issue

Post by Dewalrus »

Thanks for the reply, that's quite helpful. Since all the other dummy lights in the level work as intended, I've deleted and replaced the one that didn't and playing through to see how that comes out when exported. If that doesn't fix it then I'll go to a different light source as you suggest.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Spawner activation issue

Post by minmay »

Objects with minimalSaveState are effectively respawned at their position when the game is loaded. So any changes to world position, components (including enabling/disabling them) or anything else other than moving the object with setPosition() or outright destroying it, will not be saved, and onInit hooks will run again, etc.

However, dummy_light does not have minimalSaveState. It's also not actually a light, it's just a particle system:

Code: Select all

-- dummy particle light for low quality rendering mode
defineObject{
	name = "dummy_light",
	components = {
		{
			class = "Particle",
			particleSystem = "dummy_light",
			offset = vec(0, 0.5, 0),
		},
		{
			class = "Controller",
			onActivate = function(self)
				self.go.particle:enable()
			end,
			onDeactivate = function(self)
				self.go.particle:disable()
			end,
			onToggle = function(self)
				if self.go.particle:isEnabled() then
					self.go.particle:disable()
				else
					self.go.particle:enable()
				end
			end,
		},
	},
	placement = "floor",
	editorIcon = 88,
}
How are you deactivating the dummy_light? Merely setting the initial state to "Deactivated" in the editor might not work, since there is no onInitialDeactivate hook.

In general I strongly recommend reading the definitions of assets before using them. The people who don't do this invariably release broken mods.
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.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Spawner activation issue

Post by Azel »

Dewalrus wrote:Thanks for the reply, that's quite helpful. Since all the other dummy lights in the level work as intended, I've deleted and replaced the one that didn't and playing through to see how that comes out when exported. If that doesn't fix it then I'll go to a different light source as you suggest.
Cool. Is there a reason you are connecting a Lever to a Spawner in order to turn On the Dummy Light? After posting my first response I remembered that the update to my Mod uses a whole bunch of Dummy Lights at the top of a Light House. I turn them On/Off using a Lever inside the Light House. I just exported my Dungeon and tested it out, Saving and Reloading multiple times and everything works properly.

I tie the Lever's Activate Connector to a TurnOnLighthouse Function, and the Lever's Deactivate Connector to a TurnOffLighthouse Function.

Here is the LightsOn Function that the Lever calls:

Code: Select all

function TurnOnLighthouse()

	for count = 1,20 do
		local light = findEntity("dummy_light_" .. count);
		
		if light ~= nil then
			light.particle:enable();
		end
	end
end
In this case, I have 20 lights at the top of my Light House, named dummy_light_1 thru dummy_light_20, respectively. Turning these lights on/off is simply a matter of Enabling/Disabling the Particle property. Maybe this will help point you in the right direction if you still end up with the problem. :D

And since minmay is in this thread I should put a Disclaimer: my Script is definitely not WWMD Approved (What Would Minmay Do).

Cheers!
Post Reply