Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Animation script needed

Ray Musketeer
Registered User
Join date: 22 Oct 2005
Posts: 418
09-07-2006 06:20
hi all,
currently using as animator script I manipulated for playing a guitar when worn. Touch start starts the anim fine just want a touch stop & reset so it will stop when touched & start again on touch. This was a free script I picked up somewhere and was manipulating to run my anim would like to keep most of it since it has multiple anim potential ( I delected all the anims that were in the script initially and added the reset at the end), any help would be greatly appreciated;

//integer gToggle = 0;
integer gAnimNumber;
integer gTotalAnims;
integer gTotalAnims2;
integer gInList2;

string gAnimName = "guitar3Relaxed";


list gAnimations = [ "guitar3Relaxed"];
list gAnimations2 = [];

default {
state_entry() {
//llSay(0, "Init...";);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
gTotalAnims = llGetListLength(gAnimations);
gTotalAnims2 = llGetListLength(gAnimations2);
gAnimNumber = -1;
gInList2 = FALSE;
llListen(0, "", llGetOwner(), "";);
}

on_rez(integer param) {
llGiveInventory(llGetOwner(), "Animation Names";);
llResetScript();
}

listen(integer channel, string name, key id, string mesg) {
string preamble = llGetSubString(mesg, 0, 3);
if (preamble != "anim" && preamble != "stop";)
return;

integer perm = llGetPermissions();

if ( !(perm & PERMISSION_TRIGGER_ANIMATION)) {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
return;
}

list parsed = llParseString2List(mesg, [ "" ], []);
//llSay(0, (string)parsed);

string anim = llList2String(parsed, 1);

if (preamble == "stop";) {
//llSay(0, "Stopping: " + llGetAnimation(llGetOwner()));
//llStopAnimation(llGetAnimation(llGetOwner()));
if (anim == "";)
anim = gAnimName;

if (anim == "all";) {
integer i;
llSay(0, "Stoping";);
for (i=0; i<gTotalAnims; i++)
llStopAnimation(llList2String(gAnimations, i));

for (i=0; i<gTotalAnims2; i++)
llStopAnimation(llList2String(gAnimations2, i));

llSay(0, "Done.";);

return;
}

//llSay(0, "Stopping: " + anim);
llStopAnimation(anim);
return;
}

gAnimName = anim;
//llSay(0, "Animation: " + gAnimName);
llStartAnimation(gAnimName);
}

run_time_permissions(integer perm) {
//llStopAnimation(gAnimName);
//gToggle = 0;
}

attach(key id) {
integer perm = llGetPermissions();

if (id != NULL_KEY) {

if (! (perm & PERMISSION_TRIGGER_ANIMATION)) {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
else {

if (perm & PERMISSION_TRIGGER_ANIMATION) {
llStopAnimation(gAnimName);
}
}
}

touch_start(integer total_number) {
if (llDetectedKey(0) != llGetOwner())
return;

integer perm = llGetPermissions();

if (perm & PERMISSION_TRIGGER_ANIMATION) {
if (gAnimNumber != -1) {
if (gInList2)
llStopAnimation( llList2String(gAnimations2, gAnimNumber) );
else
llStopAnimation( llList2String(gAnimations, gAnimNumber) );
}


gAnimNumber++;

if (gInList2) {
if (gAnimNumber == gTotalAnims2) {
gAnimNumber = 0;
gInList2 = FALSE;
}
}
else {
if (gAnimNumber == gTotalAnims) {
gAnimNumber = 0;
gInList2 = TRUE;
}
}

if (gInList2)
gAnimName = llList2String(gAnimations2, gAnimNumber);
else
gAnimName = llList2String(gAnimations, gAnimNumber);

llStartAnimation( gAnimName );
llSay(0, "Animation: " + gAnimName);
}
else {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
{
llResetScript();
}
}
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
My two cents worth
09-07-2006 07:01
If its just On/Off behaviour, with off being the same as reset, then use two states and toggle between them on touch.

CODE

// Simplified code
state default
{
state_entry() { StopEveryThing(); }
on_rez(integer num) { llResetScript(); }
on_touch(integer num) { state Animate; }
....
}

state Animate
{
state_entry() { StartAnimation(); }
on_rez(integer num) { llResetScript(); }
on_touch(integer num) { state default; }
}

HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
09-07-2006 07:06
It would be *really* nice if people with a lengthy code would *bother* to add the php tags so that the code remains readable and is not a mess. I tok the liberty to reformat it - just indentions - this horrible mix of single line if cases with and without {} remains unaltered.

CODE

//integer gToggle = 0;
integer gAnimNumber;
integer gTotalAnims;
integer gTotalAnims2;
integer gInList2;

string gAnimName = "guitar3Relaxed";


list gAnimations = [ "guitar3Relaxed"];
list gAnimations2 = [];

default {
state_entry() {
//llSay(0, "Init...");
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
gTotalAnims = llGetListLength(gAnimations);
gTotalAnims2 = llGetListLength(gAnimations2);
gAnimNumber = -1;
gInList2 = FALSE;
llListen(0, "", llGetOwner(), "");
}

on_rez(integer param) {
llGiveInventory(llGetOwner(), "Animation Names");
llResetScript();
}

listen(integer channel, string name, key id, string mesg) {
string preamble = llGetSubString(mesg, 0, 3);
if (preamble != "anim" && preamble != "stop")
return;
integer perm = llGetPermissions();

if ( !(perm & PERMISSION_TRIGGER_ANIMATION)) {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
return;
}

list parsed = llParseString2List(mesg, [ "" ], []);
//llSay(0, (string)parsed);

string anim = llList2String(parsed, 1);

if (preamble == "stop") {
//llSay(0, "Stopping: " + llGetAnimation(llGetOwner()));
//llStopAnimation(llGetAnimation(llGetOwner()));
if (anim == "")
anim = gAnimName;

if (anim == "all") {
integer i;
llSay(0, "Stoping");
for (i=0; i<gTotalAnims; i++)
llStopAnimation(llList2String(gAnimations, i));

for (i=0; i<gTotalAnims2; i++)
llStopAnimation(llList2String(gAnimations2, i));

llSay(0, "Done.");

return;
}

//llSay(0, "Stopping: " + anim);
llStopAnimation(anim);
return;
}

gAnimName = anim;
//llSay(0, "Animation: " + gAnimName);
llStartAnimation(gAnimName);
}

run_time_permissions(integer perm) {
//llStopAnimation(gAnimName);
//gToggle = 0;
}

attach(key id) {
integer perm = llGetPermissions();

if (id != NULL_KEY) {

if (! (perm & PERMISSION_TRIGGER_ANIMATION)) {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
else {

if (perm & PERMISSION_TRIGGER_ANIMATION) {
llStopAnimation(gAnimName);
}
}
}

touch_start(integer total_number) {
if (llDetectedKey(0) != llGetOwner())
return;

integer perm = llGetPermissions();

if (perm & PERMISSION_TRIGGER_ANIMATION) {
if (gAnimNumber != -1) {
if (gInList2)
llStopAnimation( llList2String(gAnimations2, gAnimNumber) );
else
llStopAnimation( llList2String(gAnimations, gAnimNumber) );
}


gAnimNumber++;

if (gInList2) {
if (gAnimNumber == gTotalAnims2) {
gAnimNumber = 0;
gInList2 = FALSE;
}
}
else {
if (gAnimNumber == gTotalAnims) {
gAnimNumber = 0;
gInList2 = TRUE;
}
}

if (gInList2)
gAnimName = llList2String(gAnimations2, gAnimNumber);
else
gAnimName = llList2String(gAnimations, gAnimNumber);

llStartAnimation( gAnimName );
llSay(0, "Animation: " + gAnimName);
}
else {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
{
llResetScript();
}
}
}
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
09-07-2006 07:30
My 5 cents for this:

(a) Decide on one coding style - do not mix different ones when it comes to using {} in single line if or else statements.

(b) Get rid if the surplus { in 138 and the } in 140.

(c) Advice for the future: Make a *rudimentary* script for your problem and isolate. Those multifeature scripts are just distracting and have weird side effects. As is this one with listener, a touch event and an attach event that is clearly meant for a number of anims and not one.

(d) avoid an (a) and (c) combination :)

The script basically toggles between animations in lists - sounds different to what you are planning. You can, of course, try to mod it so that it works with one anim in one list but why would you buy a truck to get a can of Coke from the store?

Personally I think this script is overkill for what you want to do. Is it for an attachment - like a guitar or not? Do you really need the listener?

Let us assume it is for an attachment and let us assume nothing shall happen when you wear it and you start by touching it and you stop by touching it again. Then the script, listener removed, extra list removed and almost all ballast dropped overboard would look like this (no access to SL now so there may be errors):

CODE

integer playing; // indicates if the guitar is being played or not
string gAnimName = "guitar3Relaxed";

default {
state_entry() {
//llSay(0, "Init...");
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
playing=0;
}

on_rez(integer param) {
llResetScript();
}

run_time_permissions(integer perm) {
//llStopAnimation(gAnimName);
//gToggle = 0;
}

attach(key id) {
integer perm = llGetPermissions();

if (id != NULL_KEY) {

if (! (perm & PERMISSION_TRIGGER_ANIMATION)) {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
else {

if (perm & PERMISSION_TRIGGER_ANIMATION) {
llStopAnimation(gAnimName);
}
}
}

touch_start(integer total_number) {
if (llDetectedKey(0) != llGetOwner())
return;
integer perm = llGetPermissions();
if (perm & PERMISSION_TRIGGER_ANIMATION) {
if (playing) {
llStopAnimation(gAnimName);
playing=0;
} else {
llStartAnimation(gAnimName);
playing=1;
}
}
else {
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}

}


Now - I keep my fingers crossed that it works. If it does - isn't this much niocer to look at than the monster you try to use? Never use overpowerfull scripts when not needed.

If this works - expand this if you have additional needs.
Ray Musketeer
Registered User
Join date: 22 Oct 2005
Posts: 418
09-07-2006 08:09
Thanks for your input HTF, I will try it and see but I still want multiple anims functionality to cover other guitar anims that will grow as I make, so i can toggle between say hard rock style to a more sublte guitar style if thats understanble :-)ex. rock guitar 1, rock guitar 2 ,3 etc.. I admittedly have a mental block to scripting (many classes and still evades me lol) Again, thank you for the help and advice.

Works right, ty now multiples lol
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
09-07-2006 10:15
In this case ... the script you have works a bit different. How about a menu when you touch the guitar? You can select the anim to play and you'll also have a stop button? This way you can easily access 11 guitar poses and one stop command.

If this appeals to you just say so - I have done something like this very recently so I could offer you the code for it. And - trust me - it'll be easier to understand than the one you intend to use now (plug and play too - just drop in the anims). :)