[SOLVED] Particle Problems?

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!
Locked
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

[SOLVED] Particle Problems?

Post by MadCatter »

I am trying to create a particle object which activates the first particles, then after a delay starts the second set.

Is it possible to have an object with multiple "Particle" classes, and then start/stop them individually?

I have tried the code below, but I can't figure out how to address the different named particle classes.

Is there a specific way to address a component when there are more than one of a type? Just the name doesn't seem to work. It returns:
Error: attempt to index field 'particle_droplets' (a nil value)

Thanks for your help :)
SpoilerShow

Code: Select all

defineObject{ --light rain object
	name = "light_rain",
	components = {
		{
			class = "Particle",
			name = "particle_droplets",
			particleSystem = "light_rain_droplets",
		},
		{
			class = "Particle",
			name = "particle_splash",
			particleSystem = "light_rain_splash",
		},
		{
			class = "Particle",
			name = "particle_clouds",
			particleSystem = "light_rain_clouds",
		},			
		{
			class = "Controller",
			onActivate = function(self)
				self.particle_droplets:start()
				self.timer_1:start()
			end,
			onDeactivate = function(self)
				self.particle_droplets:stop()
				self.timer_2:start()
			end,
		},
		{
			class = "Timer",
			name = "timer_1",
			disableSelf = true,
			trigerOnStart = false,
			timerInterval = 5.0,
			onActivate = function(self)
				self.go.particle_splash:start()				
			end,
		},
		{
			class = "Timer",
			name = "timer_2",
			disableSelf = true,
			trigerOnStart = false,
			timerInterval = 5.0,
			onActivate = function(self)
				self.go.particle_splash:stop()				
			end,
		},
	},
	placement = "floor",
}	
Last edited by MadCatter on Mon Dec 22, 2014 8:20 pm, edited 1 time in total.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Particle Problems?

Post by minmay »

"self" inside the ControllerComponent refers to the ControllerComponent. The ControllerComponent has no field named particle_droplets, nor a field named timer_1.
What you want is:

Code: Select all

         class = "Controller",
         onActivate = function(self)
            self.go.particle_droplets:start()
            self.go.timer_1:start()
         end,
         onDeactivate = function(self)
            self.go.particle_droplets:stop()
            self.go.timer_2:start()
         end,
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
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Re: Particle Problems?

Post by MadCatter »

Thanks, that was it :)
Hopefully this will be in a releasable state soon.
Locked