Unable to Convert from 'TMesh' to 'Int'

BlitzMax Forums/MiniB3D Module/Unable to Convert from 'TMesh' to 'Int'

verfum(Posted 2007) [#1]
Hiya, a slight problem here rotating or generally manipulating objects which I have create, I'm extending from TEntity and using the Update() method to move my extended entities, so here is my code. Thanks for any help.

Function Create:TPlayer(file$)
Local ent:TPlayer = New TPlayer
ent.model = LoadAnimMesh(file$)
ent.EntityListAdd(entity_list)
End Function

Method Update()

If KeyDown(KEY_RIGHT)
px# = px# + 1
EndIf
If KeyDown(KEY_LEFT)
px# = px# - 1
EndIf

RotateEntity model,0,0,5 'Error here

End Method


bradford6(Posted 2007) [#2]
you need to use '.' (dot) notation to reference the instance of the Tplayer Object.

' you need to reference the instance of your TPlayer
verfum:Tplayer = TPlayer.create( filename$ )

RotateEntity verfum.model,0,0,5 'Error here

End Method



verfum(Posted 2007) [#3]
No I think you missunderstand, I'm updating the TPlayer entity within the Update Method, not outside of the Player Type, the example you have given above works fine, thats how I started, it's only since I've Extended my TPlayer and TBullet etc. from the TEntity and placed the moving and rotating commands within the Method Update(), it's only since then I've come across this error message.

How do you attach code to these message btw? I'll attach it so you can see properly.


verfum(Posted 2007) [#4]
Plus that would return a different error, like object not found. The code is finding my object but the RotateMesh command doesn't like being in the Update() Method, for some reason?


bradford6(Posted 2007) [#5]
1. please post 'runnable' code. I can't see what you are doing with that snippet. (just replace loaded 3d files with cubes/spheres. in fact I like to create my code without any files for the purpose of posting here and getting help. you can always replace the cube with your player mesh later)

2. use the forum tags <code> </code> but replace the <> with [ ]

you might want to use composition instead of inheritence here. this means create a Tplayer type but have a Tentity type inside it. (not extended)

also, if your code is looooong. use [code-box] (remove the - )


verfum(Posted 2007) [#6]
Sorry, here you go, I'll try and replace the model to a sphere in the mean time.
Strict

Import "minib3d.bmx"

Local screenX:Int=800,screenY:Int=600

Type TPlayer Extends TEntity
	Field model:TMesh

	Method CopyEntity:TPlayer(parent_ent:TEntity=Null)

	End Method
	
	Function Create:TPlayer(file$)
		Local ent:TPlayer = New TPlayer
		ent.model = LoadAnimMesh(file$)
 		ent.EntityListAdd(entity_list)
	End Function
	
	Method Update()
			
	        TurnEntity model,0,0,+5
		
	End Method
	
End Type

Graphics3D screenX,screenY,32,0

Local light:TLight=CreateLight()

Local alan:TPlayer=TPlayer.Create("meshes\box.b3d")

While Not KeyHit(KEY_ESCAPE)
	UpdateWorld
	RenderWorld
	Flip
Wend



verfum(Posted 2007) [#7]
No it still returns the same error even if it's a cube.


ksalomao(Posted 2007) [#8]
verfum, what bradford6 means about cubes is that we can test your code easier if there are no loadable files in it. Just edit in the code above: change "mesh\box.b3d" for a cube, so we can test it on our computers.


klepto2(Posted 2007) [#9]
Strict

Import sidesign.minib3d

Local screenX:Int=800,screenY:Int=600

Type TPlayer Extends TEntity
	Field model:TMesh

	Method CopyEntity:TPlayer(parent_ent:TEntity=Null)

	End Method
	
	Function Create:TPlayer(file$)
		Local ent:TPlayer = New TPlayer
		ent.model = CreateCube() 'LoadAnimMesh(file$)
 		ent.EntityListAdd(entity_list)
	End Function
	
	Method Update()
			
	        .TurnEntity model,0,0,+5
		
	End Method
	
End Type

Graphics3D screenX,screenY,32,0

Local light:TLight=CreateLight()

Local alan:TPlayer=TPlayer.Create("meshes\box.b3d")

While Not KeyHit(KEY_ESCAPE)
	UpdateWorld
	RenderWorld
	Flip
Wend


The problem lies in your type, exactly that you're extending it from TEntity and so in your update method you're in the scope of TEntity and TurnEntity is a method within the Type TEntity.
To call the correct Function you have to leave the scope of TEntity to add a point (.TurnEntity(model,x,y,z) or you have to call the models' method directly (model.TurnEntity(x,y,z) .
The last one is called with your code but instead of the correct x value you have assigned the model:TMesh to it and that caused the FLoat - TMesh error.

I hope this was understandable :)

cheers klepto2


verfum(Posted 2007) [#10]
Oh my god, do you have any idea how long I've been pondering over this!!?? thanks klepto2, it would of taken me forever to of figured that out myself! I would of got the model.TurnEntity() first I reckon.

Thanks again. I hope this wasn't a stupid question?


bradford6(Posted 2007) [#11]
this is kinda what i was referring to: not extending but using composition instead:

Strict

Import sidesign.minib3d

Local screenX:Int=800,screenY:Int=600

Global entity_list:TList = CreateList()

Type TPlayer ' don't EXTEND TEntity
	
	
	Field model:TEntity	' the player is COMPOSED of a Tentity


		
	Function Create:TPlayer(file$)
		Local ent:TPlayer = New TPlayer
		ent.model = CreateCube() 'LoadAnimMesh(file$)
 		ListAddLast(entity_list,ent)		' ent.EntityListAdd(entity_list)
	End Function
	
	Method Update()
			
	       TurnEntity model,0,0,+5
		
	End Method
	
End Type

Graphics3D screenX,screenY,32,0

Local light:TLight=CreateLight()
Local cam:Tentity = CreateCamera() ; MoveEntity cam,0,0,-5
Local alan:TPlayer=TPlayer.Create("meshes\box.b3d")

While Not KeyHit(KEY_ESCAPE)
	
	For Local  this_player:Tplayer = EachIn entity_list	' cycle through all TPlayers
		this_player.update()		'	call the player's update function
	Next
	UpdateWorld
	RenderWorld
	Flip
Wend



verfum(Posted 2007) [#12]
I'll give your way a go bradford, I've just found out that the Update() Abstract in TEntity isn't used as an update in the UpdateWorld, which I thought it may of been? So you do have to use:
For Local  this_player:Tplayer = EachIn entity_list	' cycle through all TPlayers
		this_player.update()		'	call the entities update function
	Next

Which isn't bad just thought for some reason the Update was ran in UpdateWorld.


bradford6(Posted 2007) [#13]
no.
Updateworld deals with collisons and animations.
Renderworld deals with drawing the entities at their current position/rotation.

there are many ways to construct a program like this and I am eager to help. what is your game going to do?


verfum(Posted 2007) [#14]
Sorry for the delay on reply, been stuck into it. It's basicaly a top down Stargate SG1 type game, you eventually can choose who you want to be, Go'ould, Ori, Human, Ancient and Wrath, you start with a minimal ship and build your way up. Mostly I'd like it to be primarily a network game.

I'm experiencing problems with the Minib3d, for starters I dont think it supports CreateListener, so my projectiles cant get louder and quiter as they move toward you. The EntityFX doesn't seem to work perfectly, I can get my objects to full bright. And full oop is proving awkward to work with, I tried to .CopyEntity(p.currentWeapon.model) Under Create:TBullet And I still get the Cant convert from TMesh to Int ???

I think it's teething problems moving from B3D to BMax.


bradford6(Posted 2007) [#15]
make sure you are explicitly 'type-ing' your variables:

b:Tbullet = copyentity(p.curr...)

vs

b = copyentity(p.curr...)


verfum(Posted 2007) [#16]
Yeah I am, one lesson I learnt the hard way LOL! Here is the TBullet Type:
	Function Create:TBullet(p:TPlayer)
	Local ent:TBullet = New TBullet
	ent.px = p.px
	ent.py = p.py
	ent.pz = p.pz
	ent.yaw = p.yaw
	ent.thrust = p.currentWeapon.thrust
	ent.model:TMesh = .CopyEntity(p.currentWeapon.model)
	ent.EntityListAdd(entity_list)
	.RotateEntity ent.model,0,ent.yaw,0
	.PositionEntity ent.model,ent.px,ent.py,ent.pz
	Return ent
	End Function

I'm guessing that I cant Extend my Types from the TEntity Type, I think I'll have to write my Types the way you have suggested above, by including the TEntity within the Types, not extending. For some reason I dont think it likes the CopyEntity being called within the Type.


verfum(Posted 2007) [#17]
Okay it worked, for some reason the CopyEntity Function doesn't like being called within an Extended Type.


klepto2(Posted 2007) [#18]
have you tried it this way?
p.currentWeapon.model.CopyEntity()


but as said before, extending internal types isn't a good idea. It is better to create a wrapper type:

Type TBullet
Field mesh:TMesh
Field ...
'bullet properties



verfum(Posted 2007) [#19]
Oh, I didn't try that, I'll have that a go, but like you said, a wrapper will be best.


bradford6(Posted 2007) [#20]
from an OOP standpoint what we are talking about is the difference between Inheritance, Composition and Aggregation.
Inheritance is the
Type TRabbit Extends TAnimal

TRabbit would generally be able to use the code [the behaviors and attributes] from TAnimal. A Rabbit "is an" Animal.

Composition is a form of "Has-a". A Type is made up of other types.
Type TSpaceship
     Field Weapon:TWeapon
     Field ShipEntity:Tentity
end type


Aggregation is very similar to Composition. The major difference (the litmus test) is:
"If the base type is destroyed, do the composed types live on?"

A common example would be a duck pond:

Type TPond
     Field List_of_Ducks:TList
End type


If the Pond is destroyed (drained, whatever) the Ducks would continue to exist.

anyway. You will probably use a combination of Inheritance and Composition/Aggregation but From what I have read (just enough to be dangerous) you should Favor Composition over inheritance.