EntityCollided and EntityName

Blitz3D Forums/Blitz3D Beginners Area/EntityCollided and EntityName

fox95871(Posted 2009) [#1]
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.




Ross C(Posted 2009) [#2]
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.


fox95871(Posted 2009) [#3]
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.


Stevie G(Posted 2009) [#4]
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"



fox95871(Posted 2009) [#5]
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: