Jump to content

Persistent Variable value for llAvatarOnSitTarget


Carbon Philter
 Share

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

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

Recommended Posts

I'm not sure if the terminology in the title is correct for my problem. Hopefully, someone can help - I just can't see the solution, though there's bound to be one.

As part of my vehicle controls, using the CHANGED LINK event, I have identified the avatar in control which allows me to report using llSay( 0, llKey2Name(captain) + " has taken command") in the vehicle set-up process.

I want to make another llSay statement on the same lines that "...... has relinquished command" when the avatar stands up, but I can't see how to make the key of the avatar survive after standing up as the CHANGED LINK event will return captain as 00000000-0000-0000-000000000000 which stops me using the llKey2Name function again.

My impersonal solution at present is to simply anonymise the stand-up statement as shown below, but if there's a way to retain the key I'd very much appreciate assistance.

Thanks in anticipation.

Carbon

 

        if (c & CHANGED_LINK)
        {
            captain = llAvatarOnSitTarget();
            if (checkAccess(captain))
            {
                        llSay(0, llKey2Name(captain) + " has command");
                        sit = TRUE;
                        llRequestPermissions(captain, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION | PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA);
                        llSay(0,"Ready to sail");
                        llMessageLinked(LINK_SET, 0, "seated", "");
                        llSleep(1);
                        llSetStatus(STATUS_PHYSICS,TRUE)                       
                 }
                else if(captain == NULL_KEY)
                {
                    llSay(0, "Captain has relinquished command");
                }

 

Link to comment
Share on other sites

Well, one simple way is to create a new global variable and save the Captain's name in it.

        if (c & CHANGED_LINK)        {            captain = llAvatarOnSitTarget();            if (checkAccess(captain))            {                        gCapnsName = llKey2Name(captain);   //  New global variable                        llSay(0, gCapnsName + " has command");                        sit = TRUE;                        llRequestPermissions(captain, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION | PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA);                        llSay(0,"Ready to sail");                        llMessageLinked(LINK_SET, 0, "seated", "");                        llSleep(1);                        llSetStatus(STATUS_PHYSICS,TRUE)                                        }                else if(captain == NULL_KEY)                {                    llSay(0, gCapnsName + " has relinquished command");                }
Link to comment
Share on other sites

So the global variable gCapnsName doesn't change even though it's created using the variable captain changes depending on the value reported by llAvatarOnSitTarget?

I thought that each iteration of the script which threw up a new value for 'captain' would feed through everything else defined from that value. I guess I haven't quite got the reasoning as to how global variables remain persistent even though they're created from changeable values.

I don't quite understand scripting. :(

Anyhow, it works a treat. Now on to the next glitch!

Many thanks once again, Rolig.

Carbon

Link to comment
Share on other sites

There's no magic.  Just follow the logic.  The changed event is triggered every time anything changes.  You are filtering it to only care about when the linkset changes the number of links and, more specifically, when an avatar sits or stands up.  So...... the avatar sits and the variable, captain, is set to the avatar's UUID. The avatar stands,  and this time llAvatarOnSitTarget() = NULL_KEY.  You clearly can't get the name of the avatar who used to be sitting on the object, because you no longer have her UUID.  It's been wiped out.  What to do?  Well, save it somewhere before she stands up.  Actually, you don't really care about the UUID itself but you know that you're going to want to remember the avatar's name.  So save it instead.  So, where can we save it?  Clearly not in the changed event, because a variable that's local to the event will get reset every time the event is triggered.  A global variable, though, doesn't get reset until you either overwrite it deliberately or reset the entire script.  It's exactly the sort of storage bin you want.  gCapnsName is loaded with the avatar's UUID when she sits down and it's still there later when she stands up.  It only changes when the next person sits down.

Link to comment
Share on other sites

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