Jump to content

Global Variables Not Updating?


GTASkinCentral
 Share

You are about to reply to a thread that has been inactive for 3515 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi guys!

I was making a quick script to detect all avatar's age in a region in days. Here is my script, only issue is, the Name and UUID that are set as global variables do not change, whilst the days that should be shown do. Any ideas?

 

integer detectionTime = 25;

integer listLength;
string  currName;
key     currID;

integer findDays(string data)
{
    integer result;
    list parse_date = llParseString2List(data, ["-"], []);
    integer year = llList2Integer(parse_date, 0);
    result = (year - 2000) * 365;
    list days = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ];
    result += llList2Integer(days, (llList2Integer(parse_date, 1) - 1));
    if (year/4 == llRound(year/4)) result += 1;
    result += llList2Integer(parse_date, 2);
 
    return result;
}

default
{
    state_entry()
    {
        llSetTimerEvent(0.1);
    }
    
    timer()
    {
        integer i;
        list    allAvatars = llGetAgentList(AGENT_LIST_REGION, []);
        integer listLength = llGetListLength(allAvatars);
        do
        {
            llRequestAgentData(llList2String(allAvatars,i), DATA_BORN);
            currName = llKey2Name(llList2Key(allAvatars,i));
            currID = llList2Key(allAvatars,i);
        }
        while(++i < listLength);
        llSetTimerEvent(detectionTime);
    }
    
    dataserver(key queryid, string data) 
    {
        integer today = findDays(llGetDate());
        integer age   = findDays(data);
        
        llOwnerSay(currName+"("+(string)currID+") was born "+(string)age+" days ago.");
    }
    
}

 

Link to comment
Share on other sites

Lets say you have 10 avatars on your sim.

The timer event in your script fires and the global variables will run through all 10 avatars while you stack 10 dataserver events at the same time.
Loop is finished and currID and currName contain the last avatar in the list.
Once the timer event is finished the script can execute other events, there are 10 dataserver events that will fire now one after the other and use currName and currID and that contains the last avatar from the list.

Your logic is faulty because you are assuming that event are interrupts. No, they are not. Events are only executed if the script is idle at that moment.

If events come in faster than they are executed they are stored in a queue. (max. 64 entries)

Link to comment
Share on other sites

try putting your loop in the data event?

adding to "i"  and querying from within the dataserver will loop for you, then check for list end and reset "I"  ...

 

integer detectionTime = 25;integer listLength;string  currName;key     currID;key query;integer findDays(string data){    integer result;    list parse_date = llParseString2List(data, ["-"], []);    integer year = llList2Integer(parse_date, 0);    result = (year - 2000) * 365;    list days = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ];    result += llList2Integer(days, (llList2Integer(parse_date, 1) - 1));    if (year/4 == llRound(year/4)) result += 1;    result += llList2Integer(parse_date, 2);     return result;} list    allAvatars; integer i ;   default{    state_entry()    {        llSetTimerEvent(0.1);    }        timer()    {         allAvatars = llGetAgentList(AGENT_LIST_REGION, []);         listLength = llGetListLength(allAvatars);         llOwnerSay("avis in region: " + (string)listLength);         query = llRequestAgentData(llList2String(allAvatars,i), DATA_BORN);                  llSetTimerEvent(detectionTime);    }        dataserver(key queryid, string data)     {      if ( queryid == query)        {            integer age   = findDays(data);                currName = llKey2Name(llList2Key(allAvatars,i));            currID = llList2Key(allAvatars,i);                    llOwnerSay(currName+"("+(string)currID+") was born "+(string)age+" days ago.");            ++i;              query = llRequestAgentData(llList2String(allAvatars,i), DATA_BORN);                            if( i == listLength  )           { i = 0;             return;           }                      }           }    }

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3515 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...