Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Intermittent error with script - help!

Nimbus Rau
Salmon pie? Where?
Join date: 15 Apr 2007
Posts: 292
09-19-2007 17:26
My scripting skills are fairly rudimentary - I'm still at the learning-to-script-by-cut-n-paste stage, so likely this problem is something that can easily be solved by wiser heads than mine. The problem is this: I have assembled the script below, which is intended to be a typing override script - when the avatar starts typing, it detects this, makes the prim in which it resides visible, and activates an animation (also included in the prim, natch). And it works... nearly all the time, both for me, and for the folk who I've given it to. But I've had two occurrences where someone else has tried to use it and it has spouted the following error or one similar:

"cat typing override: Script trying to stop animations but PERMISSION_TRIGGER_ANIMATION permission not set"

Re-logging seems to fix it, but I'd prefer that it not happen at all. I'm pretty fuzzy on how the whole getting-permission-to-run-an-animation thing works, so it's likely a problem with that. Does anyone know what I can do to fix this script and make it run smoothly ALL the time, rather than just 95% of the time?

Here's the script:
___________________________

list anims = [];
default
{
state_entry()
{
llSetTimerEvent(.1);
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);

}


timer()

{

anims = llGetAnimationList(llGetOwner());
if(llListFindList(anims,[(key)("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9";)]) != -1)
{
llSetText("",<1,0,0>,1);
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
llStartAnimation("cat-typing";);

}
else {
llSetText("",<1,1,0>,1);
llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
llStopAnimation("cat-typing";);
}
}
}
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
09-19-2007 17:38
I think you need to make an attach() event, and put the permission request there. That way, when a person attaches, it gets the permission automatically. Where you have it now, the request is only made when the script is reset.

On the other hand, you could just reset the script on_rez, or on owner change.

If you use the attach event, note the if/else check in the example script at this wiki page (so you don't request permission on detach).

http://lslwiki.net/lslwiki/wakka.php?wakka=attach
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
09-19-2007 19:49
Sorry to bring this up, but I've seen this or a very similar keyboard script a few times and it's, uh, "suboptimal." Calling llGetAnimationList ten times a second and actually processing the returned list is... well, it's not the best approach. Instead of wading through the list of all animations playing on an avatar hunting for a full key match, it's way quicker and easier to just test the result of llGetAgentInfo() to see if the AGENT_TYPING bit is set. It'll be much faster, too, so one might consider extending the timer interval--as much as possible.

I don't mean to discourage "learning-to-script-by-cut-n-paste" at all; it's just that some sources aren't the best raw material--and it's sorta impossible to know where the "gotchas" are at first.
Nimbus Rau
Salmon pie? Where?
Join date: 15 Apr 2007
Posts: 292
09-19-2007 19:58
From: Qie Niangao
Sorry to bring this up, but I've seen this or a very similar keyboard script a few times and it's, uh, "suboptimal." Calling llGetAnimationList ten times a second and actually processing the returned list is... well, it's not the best approach. Instead of wading through the list of all animations playing on an avatar hunting for a full key match, it's way quicker and easier to just test the result of llGetAgentInfo() to see if the AGENT_TYPING bit is set. It'll be much faster, too, so one might consider extending the timer interval--as much as possible.

I don't mean to discourage "learning-to-script-by-cut-n-paste" at all; it's just that some sources aren't the best raw material--and it's sorta impossible to know where the "gotchas" are at first.


Thanks for the advice! I appreciate having this sort of issue pointed out to me. As you say, it's hard to figure out these sorts of gotchas on one's own when one is a beginner at scripting.

If you have the time, is there any chance that you could perhaps show me how to do the alternate method you suggest? I'm slowly learning lsl, but my grasp of its syntax is a bit shaky as yet, and a worked demonstration would be very informative!

Thanks again. :-)
Nimbus Rau
Salmon pie? Where?
Join date: 15 Apr 2007
Posts: 292
09-19-2007 19:59
From: DoteDote Edison
I think you need to make an attach() event, and put the permission request there. That way, when a person attaches, it gets the permission automatically. Where you have it now, the request is only made when the script is reset.

On the other hand, you could just reset the script on_rez, or on owner change.

If you use the attach event, note the if/else check in the example script at this wiki page (so you don't request permission on detach).

http://lslwiki.net/lslwiki/wakka.php?wakka=attach


Those are both useful suggestions! I'll have a play with them and see if they fix the problem. Thanks!
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
09-20-2007 00:47
From: Nimbus Rau
If you have the time, is there any chance that you could perhaps show me how to do the alternate method you suggest?

If I may...

You just need to replace this bit:

anims = llGetAnimationList(llGetOwner());
if(llListFindList(anims,[(key)("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9";)]) != -1)

with this:

if (llGetAgentInfo(llGetOwner()) & AGENT_TYPING)


Here's a page from my preferred Wiki that describes llGetAgentInfo in a bit more detail:

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentInfo

---

Another thing to consider... permissions can sometimes take a second to be granted, and if your timer fires away first you'll get the same error you described. One way of dealing with that is waiting for a run_time_permissions event (the event that happens when permissions are successfully granted) before trying to animate. It might look like this (untested, sorry, not in world right now).

default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llSetTimerEvent(.1);
}
}

timer()
{
if (llGetAgentInfo(llGetOwner()) & AGENT_TYPING)
{
llSetText("",<1,0,0>,1);
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
llStartAnimation("cat-typing";);
}
else {
llSetText("",<1,1,0>,1);
llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
llStopAnimation("cat-typing";);
}
}
}

---

I didn't incorporate DoteDote's excellent suggestion, only because it would probably be more illuminating for you to check out that link and see if you can figure it out. Oh, and I'm too lazy :p

You might also think about stopping the timer again on detach with llSetTimerEvent(0.0), DoteDote's Wiki example covers both attaching and detaching. I'm not 100% sure on the flow of these events, but I suspect if the timer is never stopped it will still occasionally "beat" the granting of permissions and give you random errors.

Hope some of that helps.
Nimbus Rau
Salmon pie? Where?
Join date: 15 Apr 2007
Posts: 292
09-22-2007 19:38
Thanks for your detailed response! I'm still wrangling with the script; I was hoping to be able to post a "yup, that worked perfectly!" reply which is why the delay in responding, but I'm still trying to nut it all out. The problem is that I'm a sufficiently novice scripter that I'm still trying to figure out the syntax etc of lsl and what everything does, which makes script-debugging a painfully slow exercise for me at the moment. However, I've spent the last couple of hours going through the basic tutorials on the wiki, and they've been most helpful. With any luck, I should get this one running perfectly and gracefully Real Soon Now. *fingers crossed*