Can't get name of object

edited May 2011 in Help request
Well here's the thing. I'm using spawner to spawn enemies. Everything was fine with one, I have just simple code but now I need three enemies so I made enemy object to handle it.

I'm listening to CREATE handler and then I test if name of object is correct (enemy object name) and then do some action. Problem is, that orxObject_GetName returns name only of first object created by spawner (even if spawner is now able to create object of one type only because I don't have other two created in config), then it returns nothing and I can't do what I need if I don't know object's name.

I've already updated ORX to newest SVN version, but problem is still there.

I was using orxObject_GetName in my old simplecoded version too and everything was OK so I don't know where problem is.
void orxFASTCALL Game::Create(const orxEVENT* currentEvent){
	orxOBJECT *object = (orxOBJECT*)currentEvent->hSender;
	if (object != orxNULL) {
		const orxCHAR *name = orxObject_GetName(object);
		orxLOG("Name is: %s", name);

I tried to connect my Create function to SPAWN handler (no need to check name of created object), but it always crashed when I used object


  • edited May 2011
    you should use the macro orxOBJECT which will help you to check whether the structure is object at the same time.
    orxOBJECT *object = orxOBJECT(currentEvent->hSender);

    if (object == 0){

    are you sure you define the macro __orxDEBUG__ when using orxd lib, while remove the macro when using orx lib.
  • edited May 2011
    I'm testing object to orxNULL whch is the same i think and it's actual object cause it returns true.

    I'm just probably listening to wrong handler or something.
  • edited May 2011
    Laschweinski's right about using the macro orxOBJECT(): it's the equivalent to a C++ dynamic cast and will make sure the structure you're casting is really an orxOBJECT and not something else.

    That being said, I'm afraid I need more details about the code/config than just the example you pasted here.

    Also note that the hSender for the orxEVENT_TYPE_SPAWNER/orxSPAWNER_EVENT_CREATE event is an orxOBJECT, but for all other orxEVENT_TYPE_SPAWNER, it's an orxSPAWNER.
  • edited May 2011
    Well, I just added comparation for empty name, was working for something else and now I tested it (without any changes) and orxObject_GetName() returns object name without any problems. Kind of weird.
  • edited May 2011
    It is indeed weird. Maybe today has a better planet alignment? ;)
  • edited May 2011
    Well, for me it's still same day :-) Maybe I "accidentally" changed something :-)
Sign In or Register to comment.