Archived

This topic is now archived and is closed to further replies.

Xgkkp

Getting information from GetObjectsInSight

Recommended Posts

Xgkkp    122
Okay, so the declaration is:
bool GetObjectsInSight(int objIdx, int &objectType, float &direction, float &distance); 
Now, How do I actually get values from this? int *ObjectType i would get but &? When I say:
GetObjectsInSight (Curitem, &(Objects[Curitem]->type), .... 
It gives me an error I have never come across before:
error C2664: ''GetObjectsInSight'' : cannot convert parameter 2 from ''int *'' to ''int &''
        A reference that is not to ''const'' cannot be bound to a non-lvalue
 
I know It''s not an error on the interfaces part, so what am I not doing?

Share this post


Link to post
Share on other sites
idinkin    100
Just declare an integer and pass it to the function as argument.
For example:

int objtype;
GetObjectsInSight (Curitem, objtype), ....



Share this post


Link to post
Share on other sites
caffeineaddict    633
Hi, I am trying to get info from the function as well, but i have no idea how to get it out, I guess i''m doing it completely wrong.
Here''s the code i''m trying to use to get info i want...

int type;
float direction, distance;
g_pCore->TurnLeft(TURN_SLOW);
int objects = g_pCore->GetNumObjectsInSight();
for(int n=0; n<objects; n++)
{
Say("%d objects in view", n);
}
g_pCore->GetObjectsInSight(n, type, direction, distance);
if(type = OBJ_ENEMY)
{
g_pCore->SelectWeapon(WEAPON_GUN);
g_pCore->Fire();
}

When i try to run this it has an error and crashes the application, I really don''t know what i''m doing wrong, so any help is appreciated.

Share this post


Link to post
Share on other sites
JohnBSmall    881
quote:
Original post by caffeineaddict
Hi, I am trying to get info from the function as well, but i have no idea how to get it out, I guess i''m doing it completely wrong.
Here''s the code i''m trying to use to get info i want...
int type;
float direction, distance;
g_pCore->TurnLeft(TURN_SLOW);
int objects = g_pCore->GetNumObjectsInSight();
for(int n=0; n<objects; n++)
{
Say("%d objects in view", n);
}

g_pCore->GetObjectsInSight(n, type, direction, distance);

if(type = OBJ_ENEMY)
{
g_pCore->SelectWeapon(WEAPON_GUN);
g_pCore->Fire();
}


When i try to run this it has an error and crashes the application, I really don''t know what i''m doing wrong, so any help is appreciated.

There''s a lot wrong with that code. Here''s what I can see (not in order):

  • You have the wrong number of parameters to g_pCore->GetObjectsInSight(). Presumably you haven''t got the latest release (or aren''t using the correct interface version).

  • You''ve got "if (type = OBJ_ENEMY)", this will always evaluate to true. You should have "if (type == OBJ_ENEMY)"

  • Your code for getting the object information is outside your loop, but you''ve got a call to your Say() function in the loop. I assume you meant to call g_pCore->GetObjectsInSight() for each item, which this code won''t do (in fact, without thinking this through very carefully, I think it will try to check an item that''s one past the last item in the list, so it won''t work.

  • Your call to Say() has the string "%d objects in view", but in fact it will tell you the current item number, not the number of objects in view, because your second parameter is ''n'', not ''objects''


John B

Share this post


Link to post
Share on other sites
liquidAir    314
Well, here''s how i did mine; I think it''s kinda sloppy/buggy, but I''m not sure since it compiles without any errors, so please point out my mistakes...


int iNumObjectsInSight;
int iObjectType;
float fAngle, fDistance, fObjAngle;

for(int i=0; i<iNumObjectsInSight; i++)
{
g_pCore->GetObjectsInSight(i, &iObjectType, &fAngle, &fDistance, &fObjAngle);
}

switch(iObjectType)
{
case(OBJ_...)
// react/do something/stop/turn/blah blah blah

break;

// go on with the cases for all objects

}



InitGames Software
http://initgames.t35.com/

Share this post


Link to post
Share on other sites