Page 1 of 1

[SOLVED] Particle Problems?

Posted: Mon Dec 22, 2014 4:14 am
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",
}	

Re: Particle Problems?

Posted: Mon Dec 22, 2014 6:00 am
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,

Re: Particle Problems?

Posted: Mon Dec 22, 2014 5:44 pm
by MadCatter
Thanks, that was it :)
Hopefully this will be in a releasable state soon.