Compile Error..

BlitzMax Forums/BlitzMax Beginners Area/Compile Error..

po(Posted 2008) [#1]
Tells me 'Identifier SatelliteList not found.'. Am I going completely mad here, or is there something actually wrong with the code? I've got the latest syncmod.

I just know someone's going to point out something extremely obvious...
I've also got MaxGUI, not that it matters.


Jesse(Posted 2008) [#2]
SuperStrict

Graphics(640,480,0)

Tsatellite.Create()'creates firs object
Tsatellite.create()'creates second object
While Not KeyHit(KEY_ESCAPE)	

	Local s:TSatellite
	For s=EachIn Tsatellite.SatelliteList			
		s.Draw()				
	Next

	Flip;Cls
	
Wend

Type TSatellite	
	
	Global SatelliteList:TList=New TList
	
	Method Draw()
	
	End Method	
	
	Function Create:TSatellite()
	
		Local s:TSatellite=New TSatellite	
			
			SatelliteList.AddLast(s)
	
		Return s
	
	End Function	

End Type



Dreamora(Posted 2008) [#3]
Create a function DrawAll() on TSatellite like these:
Type TSAtellite
 ...

 Function DrawAll()
   for local t:TSatellite = eachin SatelliteList
     t.draw()
   next
 end function
end type


with TSatellite.DrawAll() you then can call that.

Its very bad OO design to iterate over a local list from outside the class actually and it defeats the purpose of classes complete (encapsulated functionality)


po(Posted 2008) [#4]
Ah, many thanks. Although I swear I've created the same program countless times and it always compiled as shown above?
May as well ask another OOP question: I hear people saying it's bad practice to use pointers? Perhaps I'm mixed up, but isn't this a pointer: TSatellite.field1


Dreamora(Posted 2008) [#5]
no not at all.
If field1 would store an object, then it would be a type safe reference that is handled by the Garbage Collector.

A pointer is something that points to a specific area in the RAM and thats it (which is exactly the problem). It does not enforce that the data has a specific structure, nor is the data given free until you end the program if you forget about it -> risk of memory leak if you don't know what you are doing.
BM luckily dropped pointer support for most pointers ... you can still convert objects to pointers but you will never be able to convert an adress into an Object.


po(Posted 2008) [#6]
I see. Thanks.