Aller au contenu

Photo

Counting WPs in an Area


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

#1
BloodsongVengeance

BloodsongVengeance
  • Members
  • 590 messages
heyas;

   okay, something simple; of course i can't handle it.  :P

   i have an area, and i want to pick a random waypoint in that area.  and, silly me, instead of having to manually count the waypoints i used, i want the script to do it for me!  wow, like to be scalable :X

so i have five waypoints all tagged "wp_nugchase"   i have a global variable named MaxRand.

  i'm trying to count the waypoints on a creature spawn event.  somehow, it keeps ending up just zero.

FIRST, i tried a for loop.  keep in mind i have NO IDEA if i'm formatting this right, this is how lsl does it:

object test;

for(MaxRand = 0; MaxRand<22; MaxRand++)
{
  test = GetObjectByTag("wp_nugchase", MaxRand);
  if(test == OBJECT_INVALID)  break;
}


SECOND, i tried the very scary do-while.  i really don't use these, so not sure THIS is formatted properly, either

  object test; MaxRand = 0;
    do
    {
     test = GetObjectByTag("wp_nugchase", MaxRand);
     MaxRand++;
    }
    while(test != OBJECT_INVALID);


  anyway, according to the nugs, the number of WPs counted is still 0  :/

what am i doing wrong?  :/


doofus check:  global variable delcarations go like right under the include lines, and before the custom functions, right?  :X

Modifié par BloodsongVengeance, 28 septembre 2010 - 04:42 .


#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
GetNearestObjectByTag will return an array of all objects with the tag you specify. Then, use GetArraySize to get the count of objects in that array.

You can even get an array of only those objects within the perception radius should you so desire using that function.

#3
BloodsongVengeance

BloodsongVengeance
  • Members
  • 590 messages
oh thanks a tonne!!



i saw the one function that returned a [ ] (i presume a list/array), but i had NO IDEA how to handle one of those in scripting. that'll be a lot better!



is there a way to pick a random object out of that array, using a pointer? i think that would be more direct than picking the nth random one each time.

#4
TimelordDC

TimelordDC
  • Members
  • 923 messages
Use Random to get a random integer between 0 and the array size and use it as an index to retrieve a waypoint.


#5
BloodsongVengeance

BloodsongVengeance
  • Members
  • 590 messages
um...



::bangs head on desk:: random i know how to do.... how do i access the array?



if object[] aWPs is a list/array of all the wp objects... what function do i use to fish one out?



well, i found two functions to get array indexes, but they just return ints.



is this even possible? i see functions to find an object's index# IN an array, but i dont see how to get an entry from an array by index#.



okay, for now im just gonna use array size and use the nearest nth wp like i was.

#6
BloodsongVengeance

BloodsongVengeance
  • Members
  • 590 messages
BAH!



this is still giving me a count of zero wps found.



lWPs = GetNearestObjectByTag(GetArea(OBJECT_SELF), "wp_nugchase", OBJECT_TYPE_WAYPOINT, 20);

MaxRand = GetArraySize(lWPs);



lWPs and MaxRand are global variables. (yah, i said aWPs last post :X )



what 'object' am i supposed to be plugging in for the first object in that function? i tried OBJECT_SELF (the nug), and the area.



is this how i declare a global object array?

object[] lWPs; //--an array (list) of WPs in the area





ps: i see youre using script function pages on the builder wiki. should i be using that instead of the da lexicon?

ie: http://dalexicon.net...tByTag_function