Calling a entity inside a type

Blitz3D Forums/Blitz3D Beginners Area/Calling a entity inside a type

Shredster7(Posted 2012) [#1]
Hello there!
I know this is going to sound really dumb, but I'm having a hard time comprehending how to control an entity inside of a type. I'm declaring the entity outside of the type itself, which I assumed is part of the problem, but that ultimately didn't help. See for yourself:

Please note that this is only a segment of some much larger code.
Any help is greatly appreciated. Thank you!

Last edited 2012


Yue(Posted 2012) [#2]
The object is created within a function, is thus local use of the same function. You should try this.

Type Nave
	Field X#
	Field Y#
	Field ID%
End Type 


Function NuevaNave.Nave()
	
	Local Objeto.Nave = New Nave 
	
	;Local Nave_Idex%
	
	Nave_Idex%=Nave_Idex%+1
	
	Objeto.Nave\ID%=  Nave_Idex%
	Objeto.Nave\X# = 20.0
	Objeto.Nave\Y# = 10.0
	
	Return Objeto
End Function 


Function EliminarNave(Nave.Nave)
	
	
	Delete Nave.Nave
	
End Function 

Local MiNuevaNave.Nave = NuevaNave.Nave()



Here:
MiNuevaNave.Nave\ID% = 100
Print MiNuevaNave.Nave\ID%

WaitKey()


Last edited 2012


Yasha(Posted 2012) [#3]
Yue has it bang on, you need to return the object from the function. You might also find your code cleaner if you stick to parameters to pass data into the function rather than using a global for the tankbody.

Also, don't bother with the "field initialisers" ("Field x# = 0" and so on). They don't work and are ignored by the compiler. I'm not really sure why this was neither removed nor made to work correctly, but the feature is broken and your field variables aren't getting initialised by it: you need to do it manually in the constructor.

Last edited 2012


Shredster7(Posted 2012) [#4]
Well, I went ahead and made the function return the entity as Yue suggested, and it works miraculously! Yasha's advice will also be extremely with the game I'm working on here.
Thank you both for your help! This game wouldn't be possible without you.


Yue(Posted 2012) [#5]
What the use of initializers for a bad habit I learned, because when I use variables or constants, I emphasize that the data content is integer (%), float (#) or string ($), but I think you're right yasha necesesario not use them.


Yasha(Posted 2012) [#6]
?

I didn't mean the type-tag (%, #, $, .Foo); I meant the assignment statement within the type body ("Field x = SOME_CONSTANT"). It's the assignment part that's broken. Type-tags still work correctly.


Yue(Posted 2012) [#7]
sorry i confused... =(