Jump to content

Start/stop another script within same prim


IsabellaRose Fallen
 Share

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

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

Recommended Posts

So, because of how much more I wanted my newest cups and bottles to do, I've rewritten the script, and so far, it works beautifully! There's just two details I'd like to add/change, but can't figure them out...

The first one is easy -- how do I get it so that the messages posted in local chat will only say the avatar(s)'s FIRST name(s), instead of their full names? This is purely cosmetic for me, not really necessary, but I'd love to fix it if I can!

Second problem is a bit more complicated, I think, but only because I don't really know what I'm doing...LOL
I have a second script in the bottle that contains the two animations inside (one is for the hold, the other is for the drink -- I have them as separate animations on a timer because I have a sound that plays specifically when the drinking animation plays). What I would like is for that script to be turned OFF when the 'cap' is on the bottle/cup, and turned ON when the 'cap' is taken off. Is there a way to work this out?

Here is the main script -- like I said, it works beautifully, save for those two little kinks I'm hoping I can work out -- hard to take a drink when the cap is in the way! (I took out most of the drink menu to shorten it, since other than the color params it's the same as the Apple Juice option)

key USER_KEY;
integer LISTEN;
integer DLN;
integer gCap;
integer gBottle;
integer CHANNEL;
list MENU_MAIN = ["UNCAP","CAP","FILL"];
list MENU_OWNER = ["CAP ON","CAP OFF","FILL","GENDER"];
string MENU_TEXT = "\nPlease Choose Menu Option";
list  MENU_GENDER = ["BOY","GIRL"];
list MENU_FILL = ["APPLE JUICE","GRAPE JUICE","ORANGE JUICE","MILK","CHOC MILK","SBERRY MILK"];

string  LASTCOMMAND;

string gender = "She";
string gender2 = "her";


default
{
    state_entry()
    {
    integer i;
    while (i < llGetNumberOfPrims() )
    {
        ++i;
        if (llGetLinkName(i) == "Cap")
        {
            gCap = i;
        }
        if (llGetLinkName(i) == "Bottle")

        { 
        gBottle = i;
    }
    }
    }

touch_start(integer total_number)
    {
        DLN = llDetectedLinkNumber(0);
        USER_KEY = llDetectedKey(0); 
        CHANNEL = (integer)(llFrand(-1000000000.0) - 1000000000.0); 
        LISTEN = llListen(CHANNEL, "", NULL_KEY, ""); 
        
        if (USER_KEY == llGetOwner())
        {
        
        llDialog(USER_KEY, MENU_TEXT, MENU_OWNER, CHANNEL); 
        llSetTimerEvent(60.0); 
        
        }
        else
        {
                    
        llDialog(USER_KEY, MENU_TEXT, MENU_MAIN, CHANNEL);
        llSetTimerEvent(60.0); 
        
        }
    }
    
    timer()
    {
        if (LASTCOMMAND == "UNCAP")
        {
            llDialog(USER_KEY, MENU_TEXT, MENU_MAIN, CHANNEL); 
            LASTCOMMAND = "";
        }
        if (LASTCOMMAND == "TAUNT")
        {
            llDialog(USER_KEY, MENU_TEXT, MENU_MAIN, CHANNEL);
            LASTCOMMAND = "";
        }
        else
        {
            llSetTimerEvent(0);
            LASTCOMMAND = "";
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if(message == "GENDER")
        {
            llDialog(USER_KEY, MENU_TEXT, MENU_GENDER, CHANNEL);
        }
        if(message == "BOY")
        {
            gender = "he";
            gender2 = "his";
            
            llOwnerSay("Gender set to boy.");
        }
        if(message == "GIRL")
        {
            gender = "she";
            gender2 = "her";
            
            llOwnerSay("Gender set to girl.");
        }
        if (message == "CAP OFF")
        {
            LASTCOMMAND = message;
        
            llSetTimerEvent(5); 
            
            llSay(0, name + " takes the cap off of " + (string)gender2 + " bottle."); llSetLinkAlpha(gCap, 0, ALL_SIDES);            
           llSetLinkAlpha(gCap,0,ALL_SIDES);
                
                }
                {
            LASTCOMMAND = message;

                }
            
                    
        
        if (message == "CAP")
        {
            LASTCOMMAND = message;
        
            llSetTimerEvent(0); 
            
            llSay(0, llKey2Name(id) + " places the cap on " + llKey2Name(llGetOwner()) + " 's bottle.");
           llSetLinkAlpha(gCap, 1, ALL_SIDES);
                }
         
         if (message == "CAP ON")
        {
            LASTCOMMAND = message;
                    {
                llSay(0, name + " replaces the cap on " + (string)gender2 + " bottle."); llSetLinkAlpha(gCap, 1, ALL_SIDES);
                }
                {
            LASTCOMMAND = message;
                                
                }
        
        }
       if (message == "UNCAP")
        {
            LASTCOMMAND = message;
            
                llSay(0, llKey2Name(id) + " removes the cap from " + llKey2Name(llGetOwner()) + "'s bottle."); llSetLinkAlpha(gCap, 0, ALL_SIDES);
                
                }
            
                {
            LASTCOMMAND = message;
             }
             {
        if(message == "FILL")
        {
            llDialog(USER_KEY, MENU_TEXT, MENU_FILL, CHANNEL);
        }
    if (message =="APPLE JUICE"){ llSay(0, llKey2Name(id) +" goes to fill "+ llKey2Name(llGetOwner()) +"'s bottle with apple juice. "+ (string)gender + " takes a big sip and smiles. "); llSetLinkColor(gBottle,<0.922, 0.784, 0.376>,3);} 

    }
}
}

And just in case it's needed, here's quick-and-easy animation timer I use:

string anim ="[:B.K:] Bottle Hold";
 string anim2 ="[:B.K:] Bottle Drink";
 
 default
 {
     attach(key victim)
     {
     if(victim == NULL_KEY)
     {
           llStopAnimation(anim);
           llStopAnimation(anim2);
           llSetTimerEvent(0);
           
         }
         else
         {
          llRequestPermissions(victim,PERMISSION_TRIGGER_ANIMATION);
     }
 }
 
    run_time_permissions(integer permissions)
     {
         if(PERMISSION_TRIGGER_ANIMATION & permissions)
         {
         llStartAnimation(anim);
         llStartAnimation(anim2);
         llSetTimerEvent(30);
      }
     }
 
    timer()
    {
     llStartAnimation(anim2);
     llStartAnimation(anim);
     }
 
 }

 // END //
Link to comment
Share on other sites

Neither one of those is particularly hard to do, but the "easy" one actually takes a little magic if you want to be sure that you hit all the possibilties.  So.....

Avatar names might be login names or display names, and login names might be "classical" ones like mine with a real last name of newer ones that have the last name Resident. Depending on what youy expect, getting a first name could be tricky.  If you use llDetectedName() or llKey2Name(), you will get a legacy name -- that is, a name with a space between the first and last name.  You can use

integer idx = llSubStringIndex(name," ");

to find the blank space and then say

string First_name = llGetSubString(name,0,idx-1);

to get the first name.  If you use llGetUserName() or llRequestUserName(), you will get a username -- that is, a name with a dot between the first and last instead of a blank.  So, you have to search for the dot.  If you use llGetDisplayName(), you get a display name, which might look like anything -- even true garbage with no recognizable first name.

The other question you had is relatively easy.  Unless you feel like combining the scripts -- which is what I might do -- you can just use llMessageLinked in one and a link_message event in the other to pass a flag trigger message when you want to make the second script do something (or stop doing it).

Link to comment
Share on other sites

Well, I couldn't figure out where to put the name stuff, and trying to combine the two scripts ended in simply breaking the main script altogether (glad I saved a copy of the bottle with the original script work in it!)...I'm tired and getting frustrated with it, so it's time to put it up for the night and come back to it tomorrow. I'll try to figure out how to link the two scripts since that will probably work better (I don't wanna break it again, that was really discouraging).

It would probably really help if I actually understood scripting language, huh? It's like trying to hold a conversation in Greek when all you know is a few key words...LOL

At least for every scripting trick I learn, it's another that I will know how to use in the future!

Thank you for the help!

Link to comment
Share on other sites

Modifying a complex script can be overwhelming.  It can be easier to work in modules.  In this case, don't try writing the first name code intp the big script directly.  Write yourself a tiny script off to the side that does nothing but the name stuff.  Test it.  See how it works.  When you have it doing the right things and you understand it, then paste it back into the big script.

Link to comment
Share on other sites

I got the name part to work! YAY!!

Now to figure out getting the main script to communicate with the animation script to turn it on and off...like I said, I tried combining the two scripts but it ended up breaking the whole thing, but I was tired and frustrated so I might have done it wrong. I'll try that again first, I think...saving a copy of the working script, of course!

 

In the real possibility that I can't get this to work, how exactly do I create a link_message event in the animation script to make it listen to the main one?

Link to comment
Share on other sites

The same way that you would create any other type of event.  For the syntax, look in the wiki at http://wiki.secondlife.com/wiki/Link_message .  There is an example there and in the wiki for llMessageLinked

Again, when you are confronted with a complex situation or a new approach to doing things, do a mini experiment first.  When you get your idea to work on a small, simple scale, then paste it into your real script. It also helps if you pepper your scripts with diagnostic llOwnerSay messages while you are in development.  That way, you can track what is actually in key variables, as opposed to what you think is there.  Especially in larger scripts, I often add a small function at the top of the script:

debug (string words){    llOwnerSay(words);}

and then write my diagnostic messages as, for example,

    debug ("At the start of touch_start, gAngle = " + (string)gAngle);

That way, I can turn off all diagnostic messages at once when I am done by just commenting out one line in my debug function.

 

 

Link to comment
Share on other sites

I did it!!! It took a lot of attempts and a lot of reading, a lot of re-writing and discovering what I was leaving out or what shouldn't be there, but I finally got it working perfectly...would it be sad to say I actually squealed in RL when I realized it was finally done? LOL

 

Thank you again so VERY much for all the help!!

Link to comment
Share on other sites

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