Aller au contenu

Photo

Using an object array (object [])


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
Miserere

Miserere
  • Members
  • 11 messages
I need to use the function GetNearestObjectToLocation and I'm not sure how to use it, as the object it returns appears to be a one-dimensional array of one or more objects. Here is the code description:

object [] GetNearestObjectToLocation (
location lLocation,
int nObjectType = OBJECT_TYPE_ALL,
int nNumberOfObjects = 1
)

My question is how do I actually create this object? Can someone give me an example of the line of code I would use. If it wasn't an array I would do this:

object oNPC = GetNearestObjectToLocation(stEvent.lTarget, OBJECT_TYPE_CREATURE);

I only want the first creature it finds, and obviously my code is incorrect. I just don't know how to declare the array.

#2
Sarcen

Sarcen
  • Members
  • 38 messages
object[] oNPCList = GetNearestObjectToLocation(stEvent.lTarget, OBJECT_TYPE_CREATURE);

if ( GetArraySize(oNPCList) > 0 )

{

object oNPC = oNPCList[0];

/* do something with oNPC here */

}


#3
Miserere

Miserere
  • Members
  • 11 messages
Thanks, I'll give that a go.