Ramen's Scripting Questions... - SLUniverse Forums
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting » Ramen's Scripting Questions...


Scripting Discuss scripting and programming for SL and other platforms

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2018, 03:11 PM   #1 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
Ramen's Scripting Questions...

I'm working on a script project, obviously, partly as an effort to learn how to better do scripting. Anyway, instead of making individual threads, I'm just going to use one thread and ask questions on it here as they come up.

So, here is the first question.


So, I'm having a bit of trouble, and it's probably stupid simple. This is part of a larger script. It is controlled on and off toggled by a button, that will be part of a HUD eventually.

When turned on, the object appears, then over time changes textures on various states before reaching an end point. This process can be stopped at any time by toggling the button off.

When toggled off, I'm trying to get the object to give a (static) version of itself to the person who turned it off. I've created static non scripted copies and put them in the object with different names.

The "off" script is below.

if(message=="pprem")
{
llOwnerSay("Tell Owner of Action");
llGiveInventory(llDetectedKey(0),"ItemInInventory" );
llResetScript();
}

It works to turn the script off, but it doesn't give anything. Everything I can find online suggests that this is the format of how llGiveInventory works. Using the button, the receiver would be the owner/wearer, but I'm also working on adding a touch target to the object so anyone can touch it and receive the copy of said item.

Suggestions on what's wrong? Is the item name supposed to be a UUID (or can it be, because I could do that).
__________________
--
Ramen Jedburgh

http://allaroundthegrid.blogspot.com/
Ramen Jedburgh is offline   Reply With Quote
Old 02-08-2018, 03:28 PM   #2 (permalink)
The Purple
 
Chalice Yao's Avatar
Adoring goats.
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 9,097
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Hmh. There are a few important things to remember:

* The receiving avatar must not be in busy/unavailable mode
* The object that is to be given must be transfer-okay from the owner to the receiving avatar (no worries if it's the same avatar)
* The "ItemInInventory" name might be case-sensitive. Doublecheck the spelling.

Also, a question:
You have an llOwnerSay, yet you do llGiveInventory(llDetectedKey(0)...

If only the owner can push the button, use llGiveInventory(llGetOwner()

If anyone can push the button, change the llOwnerSay() to llRegionSayTo(llDetectedKey(0),0,message);. Unless it was supposed to only notify the owner of the giver in the first place
__________________
"Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?" - George Carlin
Chalice Yao is offline   Reply With Quote
1 User Said Thanks:
Old 02-08-2018, 03:53 PM   #3 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
The OwnerSay may be a placeholder. Its for some roleplay sort of device, so its not super necessary for anyone but the owner to receive emotes.
Ramen Jedburgh is offline   Reply With Quote
Old 02-08-2018, 04:35 PM   #4 (permalink)
Senior Member
 
Sei Lisa's Avatar
My first name is Sei
 
Join Date: Aug 2013
Posts: 234
My Mood:
Is that snippet within a touch event, in the first place? llDetectedKey(0) only makes sense inside touch/collision/sensor events; however, the ...message=="pprem" part suggests you're using a listen event.
__________________
Tools for scripters that I'm the maintainer of:
LSL-PyOptimizer (NEW: Try it online!) | LSL Calculator | Unofficial LSL Reference Wiki | LSL Keywords Database
Sei Lisa is offline   Reply With Quote
1 User Said Thanks:
3 Users Agreed:
Old 02-08-2018, 05:01 PM   #5 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
Quote:
Originally Posted by Sei Lisa View Post
Is that snippet within a touch event, in the first place? llDetectedKey(0) only makes sense inside touch/collision/sensor events; however, the ...message=="pprem" part suggests you're using a listen event.
That could be the problem. The listen message is inside a listen event, the object reacts based on messages received.

Turning it "off" just resets the script.
Ramen Jedburgh is offline   Reply With Quote
Old 02-08-2018, 05:29 PM   #6 (permalink)
*blink*
 
Soen Eber's Avatar
Vatican mole
 
Join Date: Oct 2009
Location: Minneapolis, Minnesota, USA
Posts: 7,095
My Mood:

Awards: 1
SLU Creepy Avatar Competition 2014 Participant 
I set a global key to hold the key value from a detect, and then set it to NULL_KEY (I think that's the constant) when the activity requiring it is performed. Variables returned by detects are local to the specific event they are called in, and those events typically have no return value (at least in my experience) so you have to save them off to a global value somewhere.

That also means you have to be vigilant about clearing that global value ASAP once it is used (remember to clear it if it isn't used but no longer needed as well), to make sure you don't have a "dead" value in there. Otherwise you'r going to have a really, really fun debugging session some days/weeks/months down the line when your code finally does something you don't like and the code base has grown by several hundred lines. Those kinds of bugs don't reveal themselves immediately unless you're very lucky.

I'm probably 80% right with some of this, so wait for someone to vet/correct what I just said off the top of my head.
__________________
Hey troll, don't you have a rapture to pray for or some poor people to run over or some beatitudes to ignore or newspapers to burn or something?

You can wish-list items and return to SLU to purchase through the affiliate link.
Note: Some people refuse to buy from Amazon due to predatory tactics against publishers as noted here and here by Jacqueline Trudeau.

Last edited by Soen Eber; 02-08-2018 at 05:39 PM.
Soen Eber is offline   Reply With Quote
Old 02-08-2018, 05:43 PM   #7 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
I will look into that.

Is that global key something sharble by scripts? Because a later question once I get the basic functions ironed out is on ways to ensure different sets of objects (HUD+ item) don't interact with other sets of objects owned by other people.

Right now for testing, everything just works off channel 10, and multiple objects get controlled by the same button, though they should not be. Eventually this will need to, I dunno, select and share a random channel, or pass a key value around in a set.
Ramen Jedburgh is offline   Reply With Quote
Old 02-08-2018, 05:48 PM   #8 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
So here is the general idea.

Its not exactly what I am making, but the same code could be used for it, and I may reuse the code to make it.

Say you have a dagger. An avatar wears the dagger, which initially is invisible.

When they are stabbed, either by someone else, or themselves with the HUD, done via communication on a channel, the dagger "appears" and sends messages occasionally about being wounded more. Maybe occasionally emitting some blood particles.

The dagger can be removed by the owner, or another person (by touching it). The person removing, receives a copy of the dagger.
Ramen Jedburgh is offline   Reply With Quote
Old 02-08-2018, 06:05 PM   #9 (permalink)
*blink*
 
Soen Eber's Avatar
Vatican mole
 
Join Date: Oct 2009
Location: Minneapolis, Minnesota, USA
Posts: 7,095
My Mood:

Awards: 1
SLU Creepy Avatar Competition 2014 Participant 
Each object will have it's own UUID. You can create a channel ID specific to an object, create a value based off the object's UUID as a chat channel - this is shown in the dialog example at the lsl portal site (which you should bookmark and use).
Soen Eber is offline   Reply With Quote
1 User Said Thanks:
Old 02-09-2018, 04:53 AM   #10 (permalink)
Senior Member
 
Sei Lisa's Avatar
My first name is Sei
 
Join Date: Aug 2013
Posts: 234
My Mood:
Here's what I believe Soen is trying to say:

PHP Code:
key Toucher// this is a global variable because it is not in any {} block
// (global variables can be read and set by any part of the script and
// preserve their value until you change them or reset the script)
...
default
{
    ...
    
touch_start(integer num_touchers)
    {
         
// This stores the key in our global, so we can read it later
        
Toucher llDetectedKey(0);
        ...
    }

    
listen(integer channelstring namekey idstring message)
    {
        ...
        
// Here we check that Toucher was previously set.
        
if (message=="pprem" && Toucher != "")
        {
            
llOwnerSay("Tell Owner of Action");
            
// Here we use Toucher, which is the key we stored in the
            // touch_start event.
            
llGiveInventory(Toucher"ItemInInventory"  );
            
llResetScript();
        }
        ...
    }
    ...

Since you reset the script at the end, the global will be cleared, at least in that code path. Make sure other code paths within the listen event clear it or reset the script as well.

EDIT:
Ultimately it depends on the rest of the script, but if that is a reply to a dialog ("pprem" sounds weird for a dialog button, though), it would be best to check the ID that you get from the listen against Toucher, and if they don't match, return without clearing anything, and if they match, clear Toucher. The listen event would then be modified like this:

PHP Code:
    listen(integer channelstring namekey idstring message)
    {
        if (
id != Toucher)
            return; 
// Don't continue with the event if they don't match.
        
Toucher ""// Clear it here. Since id equals Toucher, we don't
        // lose the value. id will be automatically cleaned up when the
        // event finishes.
        
...
        if (
message=="pprem")
        {
            
llOwnerSay("Tell Owner of Action");
            
// Here we use id, which is the key of the speaker.
            // At this point we know it matches the person who touched,
            // otherwise we would have returned above.
            
llGiveInventory(id"ItemInInventory"  );
            
llResetScript();
        }
        ...
    } 

Last edited by Sei Lisa; 02-09-2018 at 05:08 AM.
Sei Lisa is offline   Reply With Quote
1 User Said Thanks:
1 User Agreed:
Old 02-22-2018, 07:28 PM   #11 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
So, I have the basic functionality working of timed texture changing when active, the user and others can remove the item and received a copy in it's current state. It interacts with the HUD on a user unique channel.

My next big hurdle is handling the passage of time. My thought process is to use a notecard to store variables over time and between log in and log off sessions. I am considering doing two states (with a toggle in the HUD/via menu) of either tracking based on real time, or online time.

Would a notecard be a good way to track this? Essentially note the start time, then depending on the mode track online time or until a set "end time" (real time).
Ramen Jedburgh is offline   Reply With Quote
Old 02-23-2018, 01:59 AM   #12 (permalink)
Senior Member
 
Sei Lisa's Avatar
My first name is Sei
 
Join Date: Aug 2013
Posts: 234
My Mood:
I'm not sure I understand what you're suggesting to do. Do you mean to let the script write some settings to a notecard? If so, then no, scripts can't write to notecards.
Sei Lisa is offline   Reply With Quote
Old 02-23-2018, 06:14 AM   #13 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
Quote:
Originally Posted by Sei Lisa View Post
I'm not sure I understand what you're suggesting to do. Do you mean to let the script write some settings to a notecard? If so, then no, scripts can't write to notecards.
Hmmm, I was thinking they could. But thats why I am still learning.

That was what I meant though.

So how do some things retain settings when they get updated? They rerwrite the scripts don't they to a new version wouldn't they? Or at the very least they would reset the scripts. Or even retain settings between log in and log off on attachments? Relogging seems to reload the scripts in any attachments.
Ramen Jedburgh is offline   Reply With Quote
Old 02-23-2018, 06:26 AM   #14 (permalink)
The Purple
 
Chalice Yao's Avatar
Adoring goats.
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 9,097
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Quote:
Originally Posted by Ramen Jedburgh View Post
Or even retain settings between log in and log off on attachments? Relogging seems to reload the scripts in any attachments.
Nah, it doesn't. A good thing to learn is the info on this page:

Event Order - Second Life Wiki

Only things that trigger the state_entry event are a result of scripts re-setting.

Logging in *does* trigger the on_rez event - so if you have a script reset coded into that event, then...yes They will get reset on every relog.


Also, what you can use to store at least some rudimentary information independent of scripts would be the description field of the object.

What some other systems offer to customers are storage of settings into an off-SL database, or an option to print settings into chat, that the user can paste into a config notecard *after* the upgrade Essentially a configuration-export into chat.
Chalice Yao is offline   Reply With Quote
Old 02-23-2018, 08:03 AM   #15 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
That description field thing is good to know. Heck its all good to know.

Thanks.
Ramen Jedburgh is offline   Reply With Quote
Old 02-23-2018, 08:34 AM   #16 (permalink)
Not as dumb as I look
 
Rolig Loon's Avatar
More coffee, please
 
Join Date: Sep 2009
Location: In a TP
Posts: 357
SL Join Date: March 2007
Quote:
Originally Posted by Chalice Yao View Post
Also, what you can use to store at least some rudimentary information independent of scripts would be the description field of the object.
Or the description field of any child prim, or any prim property that does not change. For example, you can store integers or floats in a color vector and apply the color to the face of a prim.

If you have access to an Experience and if that Experience is available on each region where you are likely to be running your script, KVP is perhaps the best way to create non-volatile storage. There's a limit to how much data you can store in an individual KVP key, but you can create a very large number of KVP keys in an Experience. Each is preserved in SL servers, unaffected by whatever happens if your local script is reset.
__________________
I'm awake ... I think.

Look for my scripted tools and my mesh items for the home and garden in SL's Marketplace at https://marketplace.secondlife.com/stores/12305
Rolig Loon is offline   Reply With Quote
1 User Said Thanks:
Old 02-23-2018, 11:58 AM   #17 (permalink)
Senior Member
 
Sei Lisa's Avatar
My first name is Sei
 
Join Date: Aug 2013
Posts: 234
My Mood:
Beware however that storing information in attachments is not very reliable: they occasionally roll back when reattached (probably because they weren't properly saved on detach).
Sei Lisa is offline   Reply With Quote
Old 03-06-2018, 11:26 AM   #18 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
So, I've figured out this whole "store things on prims" but I had a brief glitch.

So do link numbers stay consistent so long as nothing new is linked?

I stored some variables on a linked object, number 2. After adding more dummy objects for storing variables, the original object still listed as two, but data we being stored elsewhere. I removed and re-rezed the HUD object and found it was now number 7.

I'm assuming this was just a glitch because I added prims, but my question is, so long as I don't add new objects, this should continue to be linked object 7 right?

If not I'll need to figure out how to track that otherwise.
Ramen Jedburgh is offline   Reply With Quote
Old 03-06-2018, 12:25 PM   #19 (permalink)
Squirrelly
 
Beezle Warburton's Avatar
Pancakes for all!
 
Join Date: Aug 2007
Location: USA
Posts: 17,873
My Mood:
SL Join Date: October 24, 2006
Client: Frestorm, Singularity, Official
Blog Entries: 3

Awards: 1
SLU Creepy Avatar Competition 2014 Participant 
Quote:
Originally Posted by Ramen Jedburgh View Post
So, I've figured out this whole "store things on prims" but I had a brief glitch.

So do link numbers stay consistent so long as nothing new is linked?

I stored some variables on a linked object, number 2. After adding more dummy objects for storing variables, the original object still listed as two, but data we being stored elsewhere. I removed and re-rezed the HUD object and found it was now number 7.

I'm assuming this was just a glitch because I added prims, but my question is, so long as I don't add new objects, this should continue to be linked object 7 right?

If not I'll need to figure out how to track that otherwise.
llGetLinkName()


Even if it's something as simple as putting A:, B:, etc in front of the values.

Or use llGetLinkPrimitiveParams( )
and use [ PRIM_DESC ]and [ PRIM_NAME ]

AFAIK they'll never give us llGetLinkDesc.

Last edited by Beezle Warburton; 03-06-2018 at 12:32 PM.
Beezle Warburton is offline   Reply With Quote
Old 03-06-2018, 12:56 PM   #20 (permalink)
Senior Member
 
bcBrian's Avatar
Scanned
 
Join Date: Jul 2013
Location: Daytona Beach, Fl.
Posts: 1,874
Quote:
Originally Posted by Ramen Jedburgh View Post
So, I've figured out this whole "store things on prims" but I had a brief glitch.

So do link numbers stay consistent so long as nothing new is linked?

I stored some variables on a linked object, number 2. After adding more dummy objects for storing variables, the original object still listed as two, but data we being stored elsewhere. I removed and re-rezed the HUD object and found it was now number 7.

I'm assuming this was just a glitch because I added prims, but my question is, so long as I don't add new objects, this should continue to be linked object 7 right?

If not I'll need to figure out how to track that otherwise.
Link numbers don't change arbitrarily, but the edit window is notorious for displaying wrong link numbers. You can put a script inside that has a touch event telling you which link number you touched, and will see that many times it is not what the edit window is showing.
When you relog or take into inventory and rez again for example, you will often see them corrected in the edit window. Scripts will always give you the correct link number.
bcBrian is offline   Reply With Quote
1 User Said Thanks:
Old 03-06-2018, 03:43 PM   #21 (permalink)
Senior Member
 
Sei Lisa's Avatar
My first name is Sei
 
Join Date: Aug 2013
Posts: 234
My Mood:
Also, every time you link a prim or a linkset to another, they get inserted between the root and the rest of the prims. So if one object has prims A, B and C as link numbers 1, 2 and 3 respectively, and another object has links D, E and F as links 1, 2 and 3, and you select DEF, select ABC, and link, you will get an object with prims in this order: ADEFBC, where A is root, D is link number 2, etc.

Firestorm doesn't get this right. It tends to be accurate after rezzing the object, but not after changing links. That's because the sim doesn't really tell the viewer the prim order, so what FS is doing is guesswork, and it sometimes fails at that.
Sei Lisa is offline   Reply With Quote
Old 03-06-2018, 08:39 PM   #22 (permalink)
Not as dumb as I look
 
Rolig Loon's Avatar
More coffee, please
 
Join Date: Sep 2009
Location: In a TP
Posts: 357
SL Join Date: March 2007
The bottom line is that you should usually avoid referring to links by number. Link names will never change unless you change then manually yourself. So, you can approach the challenge from either one of two directions, depending on what you are scripting. You could collect important link numbers at part of your initialization sequence:

Code:
integer i = llGetNumberOfPrims();
while (i)
{
    string strName = llGetLinkName(i);
    if (strName == "window")
    {
        iWindow = i;
    }
    else if (strName == "door")
    {
        iDoor = i;
    }
    // and so forth
    --i;
}
and then use iWindow, iDoor and any others in place of link numbers. Or, instead of collecting them ahead of time, you might identify links as you need them:

Code:
touch_start(integer num)
{
    integer iLinkNo = llDetectedLinkNumber(0);
    if (llGetLinkName(iLinkNo) == "window)
    {
        // Do window stuff
    }
    else if (llGetLinkName(iLinkNo) == "door")
    {
        // Do door stuff
    }
}
Either way is more reliable than hoping that you (or a customer) don't forget later, modify the object, and screw up the link numbers.
Rolig Loon is offline   Reply With Quote
1 User Agreed:
1 User Likes This:
Old 03-06-2018, 10:40 PM   #23 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
Thanks.

Next time I am working I will modify the scripts to use these methods.

Also this is why I am doing this project. So many aspects to get forced to learn.

I already have a little working menu that saves settings in linked prims then later get pulled by another script and passed to an attachment. Which may not seem like a lot but its seems pretty good considering I had no idea what I was doing a few months ago.
Ramen Jedburgh is offline   Reply With Quote
Old 03-27-2018, 07:08 AM   #24 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
So, I'm trying to get an idea on how to better handle listeners. I keep seeing that you need to close them, for script efficiency, but when closed, the object can't hear anything.

So I had a couple of ideas on how to handle this, maybe there is some better method or I am over thinking things.

Both are kind of similar.

Basically, say you have 2 prims, one controls the others. When Prim A needs to talk to Prim B, it could trigger a say event that just sort of says "hey hey hey hey" over and over, and Prim A has a listener that turns on and off every 10 seconds or for a second that listens for a hey. It it hears a hey, it says "I'm here", keeps the channel open, then normal communication occurs.

The other method is similar, except instead of "hey hey hey hey", Prim A just tries to send the message for say, 30 seconds, and Prim B acknowledges when it hears it. If Prim A doesn't get an acknowledgement, it spits out some sort of comm error message to the user about Prim B isn't available.
Ramen Jedburgh is offline   Reply With Quote
Old 03-27-2018, 07:11 AM   #25 (permalink)
Ginger Supremacist
 
Ramen Jedburgh's Avatar
Heya ^_^
 
Join Date: Apr 2010
Location: Illinois, USA
Posts: 6,854
My Mood:
SL Join Date: 3/9/2006
Client: Firestorm
And a second unrelated question.

You can set the description for attached prims to store or transfer data and settings. Can you set the description for an object inside the prim, that is later spawned?
Ramen Jedburgh is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On




SEO by vBSEO