Jump to content

Chat to run multiple animation scripts on multiple avatars - stupid syntax error


kari1sl
 Share

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

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

Recommended Posts

Thanks, Rolig, for telling me about the LSL Scripting Forum.

I think I've sorted my Permissions problem (thanks for the advice) but can't get past
(17,0): Error ; Syntax error
to find out.
That's the line "startListen(){" (although I understand that the real error might be from a different line0
Normally I can find the error but, I can't find this one - hoping fresh eyes might.

Thanks

//kiss when chat "/11 kiss"
default
{
on_rez(integer startParam){llStartAnimation("express_wink_emote");}
touch_start(integer startup)
{if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
{startListen();}
else
{llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);}
}
run_time_permissions(integer perm)
{
    if(perm)
    {startListen();}
    else
    {llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);}
}
startListen(){
    llListen(11, "","", "");
}
    listen(integer channel, string name, key id, string message)
{
if (message == "kiss") 
{llStartAnimation("express_kiss");}
}

 

Link to comment
Share on other sites

Ah.... You're trying to run a user-defined function, startListen, in the middle of state default. You can't do that.  That function is global.  It belongs at the head of your script, before state default opens.  You don't need that function at all, though.  All it does is open a chat channel, so just do that where you need it.

Now, you're going to run into at least two problems next.  First, you are trying to start an animation in the on_rez event, before you have requested permission.  That's going to kick up an error right away.  Second, your run_time_perrmissions event needs work. When you do your first test, you should be doing a bitwise test to see if perm matches the requested permissions mask.  That is, you want to know if perm&PERMISSION_TRIGGER_ANIMATION is true.  If it's not, there's nothing else to do.  Get rid of your else condition.  After all, that's what the else condition in the touch_start event is for. 

There are other non-fatal issues you're going to want to think about (How to shut off the listen handle when you no longer need it...... How to keep unwanted people from triggering your animation .....  ), but this will at least get your script working.  You will also want to do some aesthetic cleanup so it's easier to see how your script is structured.

Link to comment
Share on other sites

I think you mentioned this is for a hud.

When I'm making attachments that animate you (which I seem quite frequently do to), I find it simplifies life a lot to ask for animation permissions straight away and then do stuff  like opening listeners in the run_time_permissions event.

You don't, I think, need an on_rez event.  I don't see what it's going to do that the attach event won't do better.    Note that doing it my way gives you something that only works when it's attached -- which is normally what you want:

default{	state_entry()	{		if(llGetAttached()!=0){//if I'm attached			llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);		}	}	attach(key attached)	{		if(attached){//I'm attached, and it can only be to my owner			llRequestPermissions((attached,PERMISSION_TRIGGER_ANIMATION);		}	}	run_time_permissions(integer permissions)	{		if(permissions & PERMISSION_TRIGGER_ANIMATION){			//now start to do other stuff		}	}} 

 

Link to comment
Share on other sites

As a matter of style, excessive curly brackets are not recommended. While the compiler is going to ignore them anyways, they make code harder to read, so more time is spend and the ods of making an error are higher.

Compare the code below with yours for readability

 

//kiss when chat "/11 kiss"

startListen()
{
llListen(11, "","", "");
}

default{ on_rez(integer startParam)
{
llStartAnimation("express_wink_emote");
}
touch_start(integer startup) {
if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) startListen(); else llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION); }
run_time_permissions(integer perm) { if(perm) startListen(); else llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION); }
listen(integer channel, string name, key id, string message) { if (message == "kiss") llStartAnimation("express_kiss"); }

}

 

 

 

Link to comment
Share on other sites

It's never wrong to put curly brackets round conditions, of course, and I was always told to use them anyway, even if it's just a single line to execute if the condition is true (which is when they're unnecessary), because it's simpler to do that than have to remember to add them later on if you change the code to make it do two things if the condition is true (e.g. say a debug message as well as do what you want it to).

 

 

Link to comment
Share on other sites

I agree, Innula.  Curly brackets may not always be necessary, but they are a wise habit.  Even if they only enclose a single line of code, they are a visual reminder of the scope in which that code is valid. If you always use the brackets, there's less chance that you'll end up generating odd results from code that looks perfectly good but has flawed logic. 

Link to comment
Share on other sites

Chat to run multiple animation scripts on multiple avatars - can't switch between loopss (glitch #2)

Thanks (again), Rolig, I incorporated youur suggestions - and it worked!
I like Innnula's suggustion about attaching but want to get past my main goal/problem below ..

I have several loops of facial expressions (that make interesting expressions by overlapping them) anf now I'm hoping

to put them all into this chat script ... I can't figure out a "trick" to switch between them - and that later I can

use to switch among severa loops.

Any ideas?

// /11 oohh or /11 aahh but WILL NOT SWITCHinteger gCount; integer gCount1;list face = ["-", "aahh", "oohh"];list gaahh =["express_tongue_out","kiss","express_tongue_out","express_surprise_emote","express_tongue_out","express_surprise_emote","express_tongue_out","express_open_mouth","express_tongue_out"];list goohh =["express_kiss","express_open_mouth","express_kiss","express_open_mouth","express_kiss","express_open_mouth","express_kiss","express_open_mouth","express_kiss"];default{touch_start(integer startup){if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION){}elsellRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);}run_time_permissions(integer perm){if(perm&PERMISSION_TRIGGER_ANIMATION)    llListen(11, "", "", "" );}listen(integer channel, string name, key id, string message){    if (message == "-"){llListen(11, "","", "");}else if (message == "aahh"){{gCount = 0; llStartAnimation(llList2String(gaahh, 0));llStartAnimation(llList2String(gaahh, 1));}integer i = 0;    while(i < 10){{llStopAnimation(llList2String(gaahh,i-1));}{llStartAnimation(llList2String(gaahh,i+1));} {llStartAnimation(llList2String(gaahh, i+2));}    {i = ++gCount%8;}{llStopAnimation(llList2String(gaahh,i+1));} {llStopAnimation(llList2String(gaahh, i+2));}{llSay( 0, (string)gCount);}}}else if (message == "oohh"){{gCount = 0; llStartAnimation(llList2String(goohh, 0));llStartAnimation(llList2String(goohh, 1));}integer i = 0;    while(i < 10){{llStopAnimation(llList2String(goohh,i-1));}{llStartAnimation(llList2String(goohh,i+1));} {llStartAnimation(llList2String(goohh, i+2));}    {i = ++gCount%8;}{llStopAnimation(llList2String(goohh,i+1));} {llStopAnimation(llList2String(goohh, i+2));}{llSay( 0, "oohh" +  (string)gCount);}}}}}

 

Link to comment
Share on other sites

There are a bunch of problems here. The most immediate is that these loops never exit because the loop control variable, i, is manipulated to never exceed 7 (the "%" modulus 8 operation... I don't know what's even being attempted there).

But before attacking some other problems, let's back up here: A single script can only hold permissions for one avatar at a time. And assuming there are multiple avatars to be animated at the same time, you're not going to want to ask permissions every time the script wants to change animations on one or the other avatars. So you're going to want multiple scripts to perform the actual animations.

This looks a bit like it's trying to be a kind of "hugger" (minus the tricky bit of moving the avatar into position). There must be open-source hugger scripts (don't ask me where), so it may help to start there.

Taking literally the "switch among loops" problem... scripts aren't multi-threaded. If a loop is started, it's going to run to completion (or forever) within that script. To multiplex among different simultaneous processes within a single script, you use a timer() event handler and some global variables to keep track of when each process needs to do what ... a bit like writing the world's dopiest scheduler.

Link to comment
Share on other sites

In addition to the other points, the loops as you have them start and and stop the animations almost immediately.    While I don't know the effect you're trying to acheive, I'm pretty certain it's not the one the script will give

The way I would do it, I think, is start the first three animations (or however many you want to play on top of each other), then start a timer, to fire a second or so later, and in the timer event, start the next animations, and carry on like that until you want to stop the timer (either with another chat command or by keeping count of how many times it fires, and stopping it after n iterations).   I am not sure if you actually need to stop the existing animations before starting new ones  -- I would suspect not,.    Try it without stopping them, anyway, and see if you need to.

 

Link to comment
Share on other sites

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