EntityCollided and EntityName

Blitz3D Forums/Blitz3D Beginners Area/EntityCollided and EntityName

Could someone please tell me why I can't seem to get EntityCollided to work with EntityName? In the code, if you turn on the line that's currently off, it crashes. But that makes no sense, because it's just doing the same thing as the line 2 lines above it: turning an id number into a name. Why does passing it through EntityCollided make it incapable of doing that anymore? The answer's probably simple, but I can't seem to figure it out.

Graphics3D 640,480,32,1
SetBuffer BackBuffer()

Global character%=1
Global levelpart%=2
Global collisionmethod%=2
Global collisionresponse%=2

Global player1position#=0
Global player1speed#=0

camera=CreateCamera()
MoveEntity camera,0,5,-10
TurnEntity camera,20,0,0
CameraZoom camera,1.6

light=CreateLight()
TurnEntity light,67.5,-22.5,0
AmbientLight 63,63,63

Global ground=CreateCube()
ScaleEntity ground,5,.1,1
MoveEntity ground,0,-1,0
EntityColor ground,63,63,63

Global wall=CreateCube()
ScaleEntity wall,.1,1,1
MoveEntity wall,3,0,0
EntityColor wall,63,63,63
EntityType wall,levelpart
NameEntity wall,"Wall"

Global player1=CreateSphere()
ScaleEntity player1,.5,.5,.5
MoveEntity player1,0,-.5,0
EntityColor player1,127,127,127
EntityType player1,character
EntityRadius player1,.5

While Not KeyHit(1)

If KeyDown(203)
player1speed=-.1
ElseIf KeyDown(205)
player1speed=+.1
Else player1speed=0
EndIf
MoveEntity player1,player1speed,0,0

Collisions character,levelpart,collisionmethod,collisionresponse
UpdateWorld
RenderWorld

Color 127,127,127

Text 0,0,"Wall's id number is "      +wall
Text 0,15,"it's name is " +EntityName(wall)
Text 0,45,"Player1 has touched "     +EntityCollided(player1,levelpart)
;Text 0,60,"it's name is " +EntityName(EntityCollided(player1,levelpart))
Text 0,460,"Move with left and right"

Flip
Wend
End


This won't work because your referencing an entity that doesn't exist:

EntityName(EntityCollided(player1,levelpart))

Your asking blitz to return the name of an entity. Now, if you haven't collided with anything, then entitycollided(player1,levelpart) will equal 0.

So, in effect, your writing:

EntityName(0)

Which will always return an error.

But how can that be, if leaving that line of code off and running the program does get you the id number at least, the same number that EntityName translates successfully 2 lines above? Do you see what I mean? It should be doing the same thing.

What I mean is +EntityName(anything) turns anything into the name given by NameEntity with other commands, like for example +EntityName(GetParent(menubar)) would write camera on the screen, so why is it not doing the same with the EntityCollided command? The id number is present, but it's not getting translated into the name.

Firstly, remove the collisions command from your main loop. It only needs to be called once.

What Ross is saying is correct, you should be doing something like this :

Color 127,127,127

Text 0,0,"Wall's id number is "      +wall
Text 0,15,"it's name is " +EntityName(wall)

Entity = EntityCollided( player1, levelpart )
Text 0,45,"Player1 has touched "     + Entity
If Collision > 0
	Name$ = EntityName( Entity )
Else
	Name$ = "Nothing!!"
EndIf
Text 0,60,"it's name is " +Name
Text 0,460,"Move with left and right"


Okay I got it, based on what Ross said yesterday. I'll try what you suggested tonight, I can't at the library.

This is probably not the standard approach, but whatever, it works. I can now get the name of any object my character touches. Here's the code for anyone who needs it:

Graphics3D 640,480,32,1
SetBuffer BackBuffer()

Global character%=1
Global levelpart%=2
Global collisionmethod%=2
Global collisionresponse%=2

Global player1position#=0
Global player1speed#=0

camera=CreateCamera()
MoveEntity camera,0,5,-10
TurnEntity camera,20,0,0
CameraZoom camera,1.6

light=CreateLight()
TurnEntity light,67.5,-22.5,0
AmbientLight 63,63,63

Global ground=CreateCube()
ScaleEntity ground,5,.1,1
MoveEntity ground,0,-1,0
EntityColor ground,63,63,63

Global wall=CreateCube()
ScaleEntity wall,.1,1,1
MoveEntity wall,3,0,0
EntityColor wall,63,63,63
EntityType wall,levelpart
NameEntity wall,"Wall"

Global player1=CreateSphere()
ScaleEntity player1,.5,.5,.5
MoveEntity player1,0,-.5,0
EntityColor player1,127,127,127
EntityType player1,character
EntityRadius player1,.5

While Not KeyHit(1)

If KeyDown(203)
player1speed=-.1
ElseIf KeyDown(205)
player1speed=+.1
Else player1speed=0
EndIf
MoveEntity player1,player1speed,0,0

Collisions character,levelpart,collisionmethod,collisionresponse
UpdateWorld
RenderWorld

Color 127,127,127

Text 0,0,"Wall's id number is "      +wall
Text 0,15,"it's name is " +EntityName(wall)
Text 0,45,"Player1 has touched "     +EntityCollided(player1,levelpart)
Text 0,60,"it's name is "

If EntityCollided(player1,levelpart)>0
Text 0,60,"it's name is " +EntityName(EntityCollided(player1,levelpart))
EndIf

Text 0,460,"Move with left and right"

Flip
Wend
End