#### Archived

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

# Getting information from GetObjectsInSight

This topic is 5553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
Just declare an integer and pass it to the function as argument.
For example:

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

##### Share on other sites
But why doesn''t it work when I try and pass it as a member of a struct in an array?

##### Share on other sites
quote:
Original post by Xgkkp
But why doesn''t it work when I try and pass it as a member of a struct in an array?

Try doing:

GetObjectsInSight(Curitem, Objects[Curitem]->type, ...)

##### Share on other sites
It requires a reference, not a pointer.

##### Share on other sites
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 on other sites
quote:
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 on other sites
Thanks for pointing that out, i''ve got it working correctly now. Now to give the bots some prediction about where the enemy is going to be. Fun fun.

##### Share on other sites
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/

1. 1
Rutin
30
2. 2
3. 3
4. 4
5. 5

• 13
• 54
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009554
• ### Who's Online (See full list)

There are no registered users currently online

×