Jump to content

Emilee Edenflower

Resident
  • Posts

    38
  • Joined

  • Last visited

Posts posted by Emilee Edenflower

  1. 17 minutes ago, angeoco said:

    You are doing integer division there. 34968 / 65536 equals 0. If you cast one or both of them as floats it should work: (float) 34968 / (float) 65536 would give 0.533... I'm not online to test it, but that applies in lots of programming languages.

    Thanks, that worked now! I'm more of a PHP coder so it didn't even occur to me to cast them as floats if they were already integers, as this calculation works fine in PHP (I checked to make before I posted the OP to make sure my maths was correct!).

    Anyway, this now gives the right result:

    integer percentageMemory = llRound(((float)used_memory / (float)total_memory) * 100);

    :) 

    • Like 2
  2. OK, hopefully someone can help me here as whatever I do always results in a 0 (zero) output! :( 

    I'm just trying to do a simple calculation to work out the percentage of memory. It really shouldn't be so difficult, should it?? I thought maybe there was limitation with how much maths could be done in one line, so I split the two calculations up and it still doesn't work as expected. 

    The calculation should look something like: 34968 / 65536 * 100 which rounded up should be about 53%. I wasn't sure if you could use parenthesis in it or not, but it didn't work anyway (eg: (34968 / 65536) * 100)

    integer used_memory = llGetUsedMemory();
    integer total_memory = llGetMemoryLimit();
    float percentageMaths = used_memory / total_memory;
    float percentageMemory = percentageMaths * 100;
    llOwnerSay("Memory used as percentage: " + (string)llRound(percentageMemory)); //result as: "Memory used as percentage: 0"

    Any insights?

  3. Cast ray is all very new to me so this may be a silly question, but is there a way to detect the "hit" from a cast ray weapon? The traditional collision detection obviously doesn't work, and from what I do understand (if I read it right) of cast ray, it operates on a channel number type of thing between the weapon and target to detect the hit?

    So can you detect a "collision" if you don't know the original script of the weapon system for like a generic cast ray collision detection?

  4. OK, final question then to make my idea work if possible. I'd like to keep the scanner script separate just for tidiness (since I can't use an include() function) -- so can't lists be sent between scripts with a llMessageLinked ? I don't quite understand how that function works across scripts, and the examples on the docs don't really make it any clearer to me.. 

  5. I understand the need for typecasting at times, I'm just getting confused about how to do this within LSL, inside a loop whilst using llListFindList if the initial list I made isn't counted as a list of keys -_- 

    Do I need to use llList2Key on my TARGET_LIST and SEEN_LIST somehow for the llListFindList to understand the comparison of keys? I think I've been staring at this for too long now

    list    TARGET_LIST = ["0f2e3a53-b856-413f-823b-71c10ca4aa58", "3a5add55-270d-4076-9e50-d4f37f2ad8af", "a6d06686-5198-4ff7-b42e-a7b4a75aaa5d", "d4b33149-686f-4bf4-b184-e8196a258b7a", "476c19b4-011e-4781-9e98-cefafe8f8606", "3498dd86-e37d-4f43-95c0-436121705a55", "3a5add55-270d-4076-9e50-d4f37f2ad8af"];
    list 	SEEN_LIST;
    integer i = llGetListLength(SEEN_LIST);
    list 	REGION_KEYS = llGetAgentList(AGENT_LIST_REGION, []);
    integer NUM_KEYS = llGetListLength(REGION_KEYS);
    key 	id;
    
    while ((--i) >= 0)
       {
          id = llList2Key(SEEN_LIST, i);
          if (llListFindList(REGION_KEYS, [id]) < 0){
             SEEN_LIST = llDeleteSubList(SEEN_LIST, i, i);
             }
       }
    
       // check for any on TARGET_LIST, when so add to SEEN_LIST
       while ((--NUM_KEYS) >= 0)
       {
          id = llList2Key(REGION_KEYS, NUM_KEYS);
          if (llListFindList((key)TARGET_LIST, [id]) >= 0)
          {
             if (llListFindList((key)SEEN_LIST, [id]) < 0)
             {
                SEEN_LIST += [id];
                llOwnerSay(llGetDisplayName(id) + " is in your region of " + llGetRegionName() + "!");
             }
          }
       } 

     

  6. 4 minutes ago, Rolig Loon said:

    I think the real problem in your script is that llKey2Name is often turning up NULL_KEY answers when you don't expect them, so the variable this_agent_key is unreliable.

    Yeah I've swapped it now to just be a list of UUIDs and I'll convert the key to username on output in llOwnerSay instead. Just about to try it inworld now

  7. 10 hours ago, Rolig Loon said:

    Uh-oh.  I stand corrected. I don't know what I was thinking when I typed that.  You just startled me enough that I went back and checked that gate counter script that I pointed the OP to, just to be sure I didn't make the mistake there.  I didn't.  The script is right (Whew).  I just had a brain failure here today.  Thanks, Innula.

    So in light of all that, and using lists instead of strings.. does this make sense for memory checking, or does it have to be a string?

    if ((llGetListLength(TARGET_LIST) * 4.2) > llGetFreeMemory()) {
    			//Delete the oldest entry in the list which is at the front of the list
    			TARGET_LIST =  llDeleteSubList(TARGET_LIST,0,0);
            }

     

  8. 2 hours ago, ellestones said:

    the function should go something like:

    
    list ListItemDelete(list source, string item)
    {
        integer i = llListFindList(source, [item]);
        if (i >= 0)
           return llDeleteSubList(source, i, i);
        else
           return source;
    }

    It looks similar to what I've got, it's just the IF part that's a bit different, though it looks to be saying the same thing from what I can tell:

    list ListItemDelete(list mylist,string element_old) {
        integer placeinlist = llListFindList(mylist, [element_old]);
        if (placeinlist != -1)
            return llDeleteSubList(mylist, placeinlist, placeinlist);
        return mylist;
    }

     

  9. Thanks I'll check it out! I don't expect there'd be many more than 20 (at most!) in a list at any one time with what I'm planning, but you never know. Even if I don't hash my list, this part looks like it could be useful to utilise in a modified way maybe:

    if ((llStringLength( hashedNames ) * 4.2) > llGetFreeMemory()) // In case memory gets tight
                {
                    hashedNames = llGetSubString(hashedNames,3,-1); //Delete the oldest entry in hashedNames
                }

     

  10. 5 minutes ago, Rolig Loon said:

    Scripts will survive region restarts, being taken to inventory and re-rezzed, being detachd and reattached, and a variety of other things, unless you have put explicit llResetScript statements in them. 

    Thanks, that's what I was hoping :) For this script, I'm mainly just thinking in terms of people storing a list of avatar keys/UUIDs now for the purpose of the snippets posted above in this thread. I have considered using the HTTP request functions to update and retrieve data stored on a server via PHP scripts instead to make sure things are more durable and/or persistent.

  11. 2 hours ago, Rolig Loon said:

    You are using llKey2Name to get the names of agents who are no longer in the region.  That will not work.  llKey2Name will only work for agents currently in the region. 

    Ah, right thanks for the heads up. I was using names as it was a customisable list, but I suppose I could do it another way which I was considering which was to store UUIDs instead, but it just meant the list couldn't just be stored/edited in a note file as easily/human-readable. But that's fine :) 

    As for the list (however I create it now), if I store names in it as a variable -- will they be 'remembered' even after logging out if the script doesn't have any reset functions in it?

  12. OK I thought it was working.. but it still spams the chat and the SEEN_LIST doesn't remove anyone if they leave the sim. hmmm..

    Here's the code again, I tidied up a few things which were causing compiling errors

    timer()
        {
        REGION_KEYS = llGetAgentList(AGENT_LIST_REGION, []);
        NUM_KEYS = llGetListLength(REGION_KEYS);
    	   if (NUM_KEYS == 0)
    	   {
    		  SEEN_LIST = [];
    		  return;
    	   }
    
       key id;
       //llOwnerSay(llDumpList2String(SEEN_LIST, ","));
       // remove a previous seen target if no longer present on region
       integer i = llGetListLength(SEEN_LIST);
       string  this_agent_name;
       string  this_SEEN_name;
       while ((--i) >= 0)
       {
          id = llList2Key(SEEN_LIST, i);
          this_SEEN_name = llKey2Name(id);
          if (llListFindList(REGION_KEYS, [id]) < 0){
             //SEEN_LIST = llDeleteSubList(SEEN_LIST, i, i);
             SEEN_LIST = ListItemDelete(SEEN_LIST, this_SEEN_name); 
             }
       }
    
       // check for any on TARGET_LIST, when so add to SEEN_LIST
       while ((--NUM_KEYS) >= 0)
       {
          id = llList2Key(REGION_KEYS, NUM_KEYS);
          this_agent_name = llKey2Name(id);
          if (llListFindList(TARGET_LIST, [this_agent_name]) >= 0)
          {
             if (llListFindList(SEEN_LIST, [this_agent_name]) < 0)
             {
                SEEN_LIST += [this_agent_name];
                llOwnerSay(llGetDisplayName(id) + " is in your region of " + llGetRegionName() + "!");
             }
          }
       } 
    } 

     

  13. Thanks for the replies. Haven't tried it yet but I thought I might just add (since I forgot to say in the OP): TARGET_LIST is a list of predefined avatar user names you want to look for. So it's trying to cross reference agents in the region with your custom list and notify you if they enter the sim and notify you only once they arrive unless they leave and come back later. 

    Not sure if this changes how you'd respond to my code or your examples?

  14. OK so i'm probably overlooking something really simple in the logic, but I can't see it for myself right now.

    I just want the llOwnerSay("so and so is in the region") to only display once if that avi has been detected already and added to the "seen" list (unless they are removed and come back later).

    I'm sure it's something simple I'm overlooking, but any help would be nice! :) If there's a better way to do this, please suggest it also!

     

    timer(){	
    	//Recheck the region
    	REGION_KEYS = llGetAgentList(AGENT_LIST_REGION, []);
        NUM_KEYS = llGetListLength(REGION_KEYS);
    	key thisAvKey;
    	string  this_agent_name;
    	integer i;
            for (i = 0; i < NUM_KEYS; ++i) {
                thisAvKey = llList2Key(REGION_KEYS,i);
    			this_agent_name = llKey2Name(thisAvKey);
    			
    			//See if targets are in your region
    			integer listIndex = llListFindList(TARGET_LIST, [this_agent_name]);
    			//llOwnerSay((string)listIndex);
    			if (listIndex != -1)
                {
    				//Update notifation list
    				SEEN_NOTI += [this_agent_name];
    				SEEN_NOTI = ListUnique(SEEN_NOTI);
    				//llOwnerSay(llDumpList2String(SEEN_NOTI, ","));
    				if (llListFindList(SEEN_NOTI, [this_agent_name]) != -1){
    				//Only give notifation if it's not been said already!
    					llOwnerSay(llGetDisplayName(thisAvKey) + " is in your region of " + llGetRegionName() + "!");
    				}
    				//Remove from SEEN list if they leave the region
    				if (llGetAgentSize(thisAvKey) == ZERO_VECTOR){
    				llOwnerSay("removed " + this_agent_name + "from the list!");
    					SEEN_NOTI = ListItemDelete(SEEN_NOTI, this_agent_name);
    				}
    				//llOwnerSay(llDumpList2String(SEEN_NOTI, ","));
    			}
            }	
    	}

     

  15. Hi, this may be a newb question, but I'm more familiar with PHP. Is there an LSL equivalent of an "include()" function so that an object can have a larger script split up into more manageable parts and included in the main script? I'm finding it rather cumbersome to have such loooong scripts with different parts and functions all in the same place. It's getting messy trying to make a new HUD!

×
×
  • Create New...