Jump to content

Inefficient Script...please help


SEMaster Aftermath
 Share

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

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

Recommended Posts

Hello everyone, I created a gag script and everything is working, but it just seems really inefficient as my novice level is showing. I would be incredibly grateful for any feedback on how to clean this thing up some.

The major area I had difficulty with was having the "open mouth" animation continue...and that I believe is what is causing my lagging issue.

Here is the script:

string    anim = "express_open_mouth";
string    dmenuText = "\nWhat would you like to do?";
list    dmenuButtons = ["Gag","Ungag","Remove"];
integer    dmenuChan;
string    gmenuText = "\nWhat would you like to do?";
list    gmenuButtons = ["Ungag","Remove"];
integer    gmenuChan;
string    umenuText = "\nWhat would you like to do?";
list    umenuButtons = ["Gag","Remove"];
integer    umenuChan;
string    desc;
integer    gListener;
integer gag1strap1 = 14;
integer gag1strap2 = 13;
integer gag1strap3 = 12;
integer gag1strap4 = 9;
integer    gag1ring1 = 10;
integer gag1ring2 = 11;
integer gag1ball = 1;
integer gag2strap1 = 6;
integer gag2strap2 = 7;
integer gag2strap3 = 8;
integer gag2strap4 = 3;
integer    gag2ring1 = 4;
integer gag2ring2 = 5;
integer gag2ball = 2;
integer    show = 1;
integer    hide = 0;

inst()
{
    llOwnerSay("Set the strength of the gag with either a 1, 2, or 3 in description field" +
                "\n1 = no talking" +
                "\n2 = no talking, no sending IMs" +
                "\n3 = no talking, no sending IMs, no receiving IMs");    
}

showgag()
{
    llSetLinkAlpha(gag1ball,show,ALL_SIDES);
    llSetLinkAlpha(gag1ring1,show,ALL_SIDES);
    llSetLinkAlpha(gag1ring2,show,ALL_SIDES);
    llSetLinkAlpha(gag1strap1,show,ALL_SIDES);
    llSetLinkAlpha(gag1strap2,show,ALL_SIDES);
    llSetLinkAlpha(gag1strap3,show,ALL_SIDES);
    llSetLinkAlpha(gag1strap4,show,ALL_SIDES);
    llSetLinkAlpha(gag2ball,hide,ALL_SIDES);
    llSetLinkAlpha(gag2ring1,hide,ALL_SIDES);
    llSetLinkAlpha(gag2ring2,hide,ALL_SIDES);
    llSetLinkAlpha(gag2strap1,hide,ALL_SIDES);
    llSetLinkAlpha(gag2strap2,hide,ALL_SIDES);
    llSetLinkAlpha(gag2strap3,hide,ALL_SIDES);
    llSetLinkAlpha(gag2strap4,hide,ALL_SIDES);    
}

showungag()
{
    llSetLinkAlpha(gag2ball,show,ALL_SIDES);
    llSetLinkAlpha(gag2ring1,show,ALL_SIDES);
    llSetLinkAlpha(gag2ring2,show,ALL_SIDES);
    llSetLinkAlpha(gag2strap1,show,ALL_SIDES);
    llSetLinkAlpha(gag2strap2,show,ALL_SIDES);
    llSetLinkAlpha(gag2strap3,show,ALL_SIDES);
    llSetLinkAlpha(gag2strap4,show,ALL_SIDES);
    llSetLinkAlpha(gag1ball,hide,ALL_SIDES);
    llSetLinkAlpha(gag1ring1,hide,ALL_SIDES);
    llSetLinkAlpha(gag1ring2,hide,ALL_SIDES);
    llSetLinkAlpha(gag1strap1,hide,ALL_SIDES);
    llSetLinkAlpha(gag1strap2,hide,ALL_SIDES);
    llSetLinkAlpha(gag1strap3,hide,ALL_SIDES);
    llSetLinkAlpha(gag1strap4,hide,ALL_SIDES);
}

showremove()
{
    llSetLinkAlpha(LINK_SET,hide,ALL_SIDES);
}

level1()
{
    llOwnerSay("@sendchat=n");
    llOwnerSay("@emote=add");    
}

level2()
{
    llOwnerSay("@sendchat=n");
    llOwnerSay("@sendim=n");
    llOwnerSay("@emote=add");
}

level3()
{
    llOwnerSay("@sendchat=n");
    llOwnerSay("@sendim=n");
    llOwnerSay("@recvim=n");
    llOwnerSay("@emote=add");
}

free()
{
    llOwnerSay("@sendchat=y");
    llOwnerSay("@sendim=y");
    llOwnerSay("@recvim=y");
}

unlock()
{
    llOwnerSay("@detach=y");
    llOwnerSay("@touchattachself=y");
}

lock()
{
    llOwnerSay("@detach=n");
    llOwnerSay("@touchattachself=n");
}

default
{
    state_entry()
    {
        inst();
        showremove();
        desc = llGetObjectDesc();
        llOwnerSay("Description set at: " + desc);
    }
    attach(key id)
    {
        llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION);
    }
    changed(integer change)
    {
        if(change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    touch_start(integer num_detected)
    {
        llListenRemove(gListener);
        dmenuChan = (integer)(llFrand(999999.0) * -1);
        gListener = llListen(dmenuChan,"",llDetectedKey(0),"");
        llDialog(llDetectedKey(0),dmenuText,dmenuButtons,dmenuChan);
        llSetTimerEvent(60.0);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message == "Gag")
        {
            state gag;
        }
        if(message == "Ungag")
        {
            state ungag;
        }
        if(message == "Remove")
        {
            unlock();
            showremove();
            free();
            llStopAnimation(anim);
        }
    }
    timer()
    {
        llListenRemove(gListener);
    }
}

state gag
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
        showgag();
        lock();
        if(desc == "1")
        {
            level1();
        }
        if(desc == "2")
        {
            level2();
        }
        if(desc == "3")
        {
            level3();
        }
    }
    run_time_permissions(integer perm)
    {
        if(perm)
        {
            llStartAnimation(anim);
            llSetTimerEvent(0.5);
        }
    }
    touch_start(integer num_detected)
    {
        llListenRemove(gListener);
        gmenuChan = (integer)(llFrand(999999.0) * -1);
        gListener = llListen(gmenuChan,"",llDetectedKey(0),"");
        llDialog(llDetectedKey(0),gmenuText,gmenuButtons,gmenuChan);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message == "Ungag")
        {
            state ungag;
        }
        if(message == "Remove")
        {
            unlock();
            showremove();
            free();
            llStopAnimation(anim);
            state default;
        }
    }
    timer()
    {
        llStartAnimation(anim);
    }
}

state ungag
{
    state_entry()
    {
        showungag();
        unlock();
    }
    touch_start(integer num_detected)
    {
        llListenRemove(gListener);
        umenuChan = (integer)(llFrand(999999.0) * -1);
        gListener = llListen(umenuChan,"",llDetectedKey(0),"");
        llDialog(llDetectedKey(0),umenuText,umenuButtons,umenuChan);
        llSetTimerEvent(60.0);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message == "Gag")
        {
            state gag;
        }
        if(message == "Remove")
        {
            unlock();
            showremove();
            free();
            llStopAnimation(anim);
            state default;
        }
    }
    timer()
    {
        llListenRemove(gListener);
    }
}

Link to comment
Share on other sites

In terms of getting an animation to reliably run, you're better off using a looped animation and have the script check the avatar's animation list every now and then to confirm that the animation is still running.

You can optimize that script a lot more, but in terms of the issue at fault, the approach is the issue (From reading the script, you're using a non-looped animation and retriggering it every time the animation ends, which is wildly unreliable).

Link to comment
Share on other sites

How are you measuring this lag? It isn't that big a deal to push an animation every half-second. It's not great because it needs to be relayed to all viewers of the scene, but in the scale of stuff scripts do, it shouldn't be a showstopper.

Faces are relatively tricky things to keep animated, by the way. Check to be sure the built-in emote actually does what you expect on mesh heads, and that it really keeps/resumes working after other facial animations play. At some point in the past I resorted to cycling between two copies of the same animation, just to keep one of them on the top of the stack (assuming priority can't fix it all, which it rarely does in my experience).

Link to comment
Share on other sites

4 hours ago, Qie Niangao said:

Check to be sure the built-in emote actually does what you expect on mesh heads, and that it really keeps/resumes working after other facial animations play.

"express_open_mouth" is a system-head only animation. system head emotes don't work on mesh heads and mesh head anims don't work on the system head (IIRC). given that the OP must be using a system head for this to work at all, it's relatively safe to assume animation conflict isn't an issue. (as system heads don't have complicated animation scripts in them that could interfere)

  • Like 1
Link to comment
Share on other sites

11 minutes ago, Quistess Alpha said:

"express_open_mouth" is a system-head only animation. system head emotes don't work on mesh heads and mesh head anims don't work on the system head (IIRC). given that the OP must be using a system head for this to work at all, it's relatively safe to assume animation conflict isn't an issue. (as system heads don't have complicated animation scripts in them that could interfere)

Ah. That reminds me now that I used to have a little gadget that would make my avatar briefly express_smile at random intervals, which must have interrupted whatever other facial animations I was trying to present. Times were simpler then. Now we'd judge the weirdly smiling avatar as either plotting a killing spree or having digestive distress.

Edited by Qie Niangao
  • Haha 1
Link to comment
Share on other sites

I would like this to work on a mesh head, I tested it on one of the standard SL heads though, you are correct. Does anyone have a suggestion on how to get it to work with a mesh head?

As for how I am measuring the lag, not anything very official nor scientific. Just observation on my part and the assumption my script is probably a little heavy due to my minimal experience.

Link to comment
Share on other sites

15 minutes ago, SEMaster Aftermath said:

Does anyone have a suggestion on how to get it to work with a mesh head?

if it's just for personal use, you might try experimenting with some of the animations from oracul's bento enhanced head (you can copy the animations out of the HUD) otherwise the "real" answer would be to read up on the api for every major head brand to see what they expect to ask them to play a smile animation. or craft several open mouth animations tailored to each target head of interest separately.

Edited by Quistess Alpha
Link to comment
Share on other sites

Just now, SEMaster Aftermath said:

As for how I am measuring the lag, not anything very official nor scientific. Just observation on my part and the assumption my script is probably a little heavy due to my minimal experience.

The good news is that a single script generally can't cause lag, and there's nothing in your script that even approaches something that could be observable.

One non-animation related improvement I would suggest is making those link numbers "dynamic" so that if you edit the linkset and the link order changes, you won't have to edit the script. This does require that you rename the links with matching names, but that shouldn't be too difficult, since you can select multiple links and then change their name all at once.

Something like this. I've added two functions near the top, which are used in showgag(), showungag(), and state_entry.

  • Like 1
Link to comment
Share on other sites

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