Jump to content

Acces variable in start_touch via listen


Mephisto Brennen
 Share

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

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

Recommended Posts

list    mainMenu;
integer iChan = -22;
integer iLsn;
integer length;
string  main = "What would you like to do?";
string  temp;

default
{
    state_entry()
    {
       iLsn = llListen(iChan,"","","");               
    }
    
    touch_start(integer total_number)
    {    
        llOwnerSay("Touched");
    
        if(iLsn == 1) 
        {
            llDialog(llDetectedKey(0), main, mainMenu, -12);           
            llSay(0,"you made it");
        } 
         else
        {
            llSay(0, "retrieving data, one sec please");  
        }
    }
    
    listen(integer channel, string name, key id, string message){   
        if(channel == iChan) {
              temp=message;
              mainMenu=llParseString2List(temp, [", "], []);           
        }
    } 
}

So decided to finally dive into LSL after what... 15 years. About time, I guess. I am just trying to figure out how I can access my mainMenu variable in the touch_start event via the listen event, cause this causes a hickup in my script.

Long story short. I have one object that looks into its own inventory and spits out a list in string format on channel -22. If i use the llSay command with the temp message within the listen, i can get it no problem. So i comma seperated them into a list. But when I try to call up the list within my on touch event, i get nada. Occasionally i get something, but i can hardly reproduce it, so to speak i dont know where i have to look for it. I tried to build in items so i could see what happens, but it stays blank for me. If i remove the listen state event call in the state entry, i do get through the system, giving me the retrieveing data, one sec message. So something goes wrong with i guess the parsing or my code just doesnt want to handle it. Can someone take a peak?.

Script compile is fine.


 

Link to comment
Share on other sites

okay, i deactivated my other script in the other prim, and indeed, it starts working .. i am going to asume here that maybe my script is being updated to much?

default
{
    state_entry()
    {
        
        // create the loop 
        do
        {
            list inventoryItems;           
            integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);          
            integer index; 
            
            for ( ; index < inventoryNumber; ++index ){
            
                string itemName = llGetInventoryName(INVENTORY_ALL, index);
                
                inventoryItems += itemName; 
                
                inventoryItems += ", "; 
                
            }
            
            llSay(-22, (string) inventoryItems );
            
        } while (1 == 1);
        
    }
    
}

Should i build this in a timer .. or should i do a call from the other script to this script and let it respond with this? What would be best practise?

Link to comment
Share on other sites

8 minutes ago, Mephisto Brennen said:

okay, i deactivated my other script in the other prim, and indeed, it starts working .. i am going to asume here that maybe my script is being updated to much?

Should i build this in a timer .. or should i do a call from the other script to this script and let it respond with this? What would be best practise?

My first question would be, is there a reason why you need the contents constantly updated? There's probably a much more efficient setup we can create.

Your code looks correct at first glance (I'm no longer in-world to be able to test it), though you are indeed doing things a bit too often. The script is almost certainly doing more work than is necessary, which can affect the performance of all other scripts in the region. The simplest "fix" would be to add an llSleep after the llSay, to force the script to wait a few moments before doing another update.

Link to comment
Share on other sites

3 minutes ago, Wulfie Reanimator said:

My first question would be, is there a reason why you need the contents constantly updated? There's probably a much more efficient setup we can create.

Your code looks correct at first glance (I'm no longer in-world to be able to test it), though you are indeed doing things a bit too often. The script is almost certainly doing more work than is necessary, which can affect the performance of all other scripts in the region. The simplest "fix" would be to add an llSleep after the llSay, to force the script to wait a few moments before doing another update.

thank you so much for hiting at the llSleep. I had no idea that excisted (thought i had to do this via the timer event). This solves my problem. Thank you so much!

  • Like 1
Link to comment
Share on other sites

I made a check.
Seems that llGetInventoryName is slow so the script spams the list only 500 times per second with 1 object and 75 times per second with 10 objects.
The script load of the single script is comparable to objects with 20-50 scripts in.
More important: it spams the message buffer of the sim which is limited.

On a healthy sim nobody will notice something, but on a sim that runs already at the limits this script is just another griefer tool.

So using the timer is always a great idea for loops. If it lacks of scripting knowledge - at least a llSleep is needed in such loops.

Link to comment
Share on other sites

16 hours ago, Mephisto Brennen said:

okay, i deactivated my other script in the other prim, and indeed, it starts working .. i am going to asume here that maybe my script is being updated to much?



default
{
    state_entry()
    {
        
        // create the loop 
        do
        {
            list inventoryItems;           
            integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);          
            integer index; 
            
            for ( ; index < inventoryNumber; ++index ){
            
                string itemName = llGetInventoryName(INVENTORY_ALL, index);
                
                inventoryItems += itemName; 
                
                inventoryItems += ", "; 
                
            }
            
            llSay(-22, (string) inventoryItems );
            
        } while (1 == 1);
        
    }
    
}

Should i build this in a timer .. or should i do a call from the other script to this script and let it respond with this? What would be best practise?

I have 2 suggestions.

1.  Replace  "list invwntoryItems" to "string inventoryItems"

2. I recommend use  Change event trigger  http://wiki.secondlife.com/wiki/Changed
whenever you remove and add new items into object. it will trig update event. no sleep, no timer needed

changed(integer change)
    {
        if(change & (CHANGED_OWNER | CHANGED_INVENTORY)) // Either of the changes will return true.
           { 
            put your item update script here

                           }
          }

 

Edited by Jerilyn Acajou
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1153 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...