Problem with a line of code.

Monkey Forums/Monkey Programming/Problem with a line of code.

Big Jim(Posted 2011) [#1]
Could somebody please tell me what's wrong with the line marked "Troubled Line" in my code below?

Import mojo

Class Particle
	Field X#, Y#, XD#, YD#
	Field Age#  = 1.0
	Field DecayRate#
	Field GravityX# = 0.0
	Field GravityY# =0.0

	Method New(x#, y#, Scatter)
		Self.X = x
		Self.Y = y
		Self.XD = Rnd(-Scatter, Scatter)
		Self.YD = Rnd(-Scatter, Scatter)
		Self.Age = Rnd()
		Self.DecayRate = Rnd(.005, .01)
	End Method

	Method Update()
		X += XD + GravityX
		Y += YD + GravityY
		If X < 0 Or X > DeviceWidth Then Age = 0
		If Y < 0 Or Y > DeviceWidth Then Age = 0
		Age -= DecayRate
	End Method

End Class

Class ParticleEmitter
	Field Particles:= New List<Particle>
	Field Scatter#, ParticleCount
	Field GravityX# = 0, GravityY# = 0
	Field ParticleImage:Image
	Field RemainingParticles
	
	Method New(x#, y#, scatter#, particleCount, particleImage:Image, gravX#, gravY#)
		GravityX = gravX
		GravityY = gravY
		For Local i = 0 To ParticleCount	
			Particles.AddLast(New Particle(x, y, scatter))
		Next
		Self.ParticleImage = particleImage
		RemainingParticles = particleCount
	End Method
	
	Method Update()
		Local LiveParticles:= New List<Particle>
		For Local p:Particle = Eachin Particles
			p.GravityX = GravityX
			p.GravityY = GravityY
			p.Update()
			If p.Age > 0 Then LiveParticles.AddLast(p)
		Next
		Particles = LiveParticles
		RemainingParticles = Particles.Count
	End Method
	
	Method Render()
		For Local p:Particle = Eachin Particles
			SetAlpha p.Age
			SetBlend LightenBlend
			SetColor Rnd(100,255), Rnd(100,255), Rnd(100,255) 
			DrawImage (ParticleImage, p.X, p.Y,0,p.Age, p.Age)
		Next
	End Method

End Class

Class ParticleManager
	
	Field ParticleEmitters:= New List<ParticleEmitter>
	Field TotalParticles = 0
	
	Method AddParticleEmitter(x#, y#, scatter#, particleCount, particleImage:Image, gravX#, gravY#)
		''''''''''''''''''''''trouble line''''''''''''''''''''''''''
		ParticleEmitters.AddLast( New ParticleEmitter(x#, y#, scatter#, particleCount, particleImage:Image, gravX#, gravY#))
		'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	End Method
	
	Method Update()
		Local LivePE:= New List<ParticleEmitter>
		TotalParticles = 0
		For Local pe:= Eachin ParticleEmitters
			pe.Update()
			If pe.RemainingParticles > 0 
				LivePE.AddLast(pe)
				TotalParticles += pe.RemainingParticles
			End If
		Next
		ParticleEmitters = LivePE

	End Method

	Method Render()
		For Local pe:= Eachin ParticleEmitters
			pe.Render()
		Next
	End Method


End Class


I'm stumped...


Big Jim(Posted 2011) [#2]
It keeps telling me I need an ')' on that line...


Warpy(Posted 2011) [#3]
It might be the # characters - while it was ok to use them wherever in bmax, I don't think you can use them in monkey after the variable declaration.


Jesse(Posted 2011) [#4]
get rid of all of the variable definitions such as the # and the ":Image".


Foppy(Posted 2011) [#5]
To me what looks a bit strange is how you use the type-indicators following te variable names that you are passing along. I would do:
ParticleEmitters.AddLast( New ParticleEmitter(x, y, scatter, particleCount, particleImage, gravX, gravY))

But that may not be the actual problem.


Big Jim(Posted 2011) [#6]
That did the trick thanks!
I had to remove the type indicators.


therevills(Posted 2011) [#7]
Yeah when calling and using variables do not put the type next to it, only do that when you are declaring your variable in the first place (also use Strict ;)).


Samah(Posted 2011) [#8]
Yeah when calling and using variables do not put the type next to it, only do that when you are declaring your variable in the first place (also use Strict ;)).

Mark should make Strict default, and make it so that the non-Strict (current) standards require the keyword IAmALazyProgrammerWhoWantsToSaveKeystrokes. ;)


Tibit(Posted 2011) [#9]
A "lazy" keyword that you have to type? Seriously... ;)