Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Resetting script help

Zura Rozier
Registered User
Join date: 9 Mar 2007
Posts: 2
03-13-2007 17:21
Hello,

I'm having a little trouble with my script. I'm not exactly a novice programmer, but it's been a while since i've done any work with languages.

What i'm wanting to do is reset the script on rez, then when the object is clicked, play an animation and sound, then reset the script so that it can be clicked and played again. So far the anim and sound are working fine, but the resets dont seem to be happening. Pasted in is my current code. I've tried placing the llResetScript command in different places (to test and see what happens), and I've also tried creating a seperate state called after the playanim state, which only served to reset the script and return to default state.

When I attach the object and run once, it's just fine. Even if i detach and re-attach, it doesnt run

Any help is much appreciated...
Zura

string gAnimName = "BigHammer";
string gSoundName = "Squeak";

default
{
on_rez(integer start_param)
{
llResetScript();
}

state_entry()
{
llSay(0, "Looking for someone to BONK!";);
}

touch_start(integer total_number)
{
llSay(0, "Look Out!!";);
state playanim;
}

}


state playanim
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llStartAnimation(gAnimName);
llSleep(.75);
llPlaySound(gSoundName, 1);
}
}
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
03-13-2007 18:33
CODE

string gAnimName = "BigHammer";
string gSoundName = "Squeak";

default
{
on_rez(integer start_param)
{
llResetScript();
}

state_entry()
{
llSay(0, "Looking for someone to BONK!");
}

touch_start(integer total_number)
{
llSay(0, "Look Out!!");
state playanim;
}

}


state playanim
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llStartAnimation(gAnimName);
llSleep(.75);
llPlaySound(gSoundName, 1);
}
}


The problem is that you request the permissions, but then immediately try to start the animations. Try requesting permissions earlier, perhaps in state_entry of default{}.

You don't actually need two states -- could put the animations in your touch event handler.
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
03-13-2007 18:49
With the current script, it ends up stuck in the playanim state which doesn't have event handlers for touch_start or on_rez so it can't do anything after the initial sound and animation, and there's no code telling it to return to the default state either. So you could do something like this:

CODE

state playanim
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llStartAnimation(gAnimName);
llSleep(.75);
llPlaySound(gSoundName, 1);
state default;// get ready to go again
}
}


Or, you could skip the second state all together and just plop all the above code inside touch_start (minus the state change bit I added of course).

It's also not really kosher to just ask for permission then immediately play an animation; the proper way is generally to have a seperate event handler for run_time_permissions and put your animation and sound code in there. That way you're assured the permission actually got requested and granted. Your way will work most of the time, but can fail with a script error if latency prevents the permissions from being requested and granted in a timely manner.

Forum tip: wrap your code in [ php] and [ /php] tags (without the extra spaces) to get the pretty formatting like I got :)
Simil Miles
Creator
Join date: 1 Mar 2007
Posts: 300
03-13-2007 18:57
As I have understood, you want an attachment that plays an animation and a sound each time it's touched.

This is how I have done it :

CODE

string anim_BigHammer = "BigHammer";
string sound_Squeak = "Squeak";

default
{
changed(integer change)
{
if (change & CHANGED_OWNER)
{
llResetScript();
}
}

attach(key id)
{
if (id != NULL_KEY)
{
llOwnerSay("Looking for someone to BONK!"); // llSay to llOwnerSay : no spam
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}

touch_start(integer total_number)
{
llSay(0, "Look Out!!");
llStartAnimation(anim_BigHammer);
llSleep(.75);
llPlaySound(sound_Squeak, 1.0); // integer to float : valid
}
}


You usually need to llResetScript() when you use llGetOwner() in a script that you want other people than you to use.
Since it's an attachment on_rez and llResetScript() would be triggered on every login, instead I have moved llResetScript() to the attach() event handler to check if the owner changes.
The code you submitted doesn't work because nothing plays the animation and sound again, to eventually go back to the default state you should use state default; not llResetScript().
Here you don't even need more than one state.
_____________________
UnConWTech @ Flo (144, 84, 224) http://unconwtech.free.fr

SL books http://astore.amazon.com/secondlife-sl-20/

Need a beta tester for quality assurance ?
Need a translator for English, French, Spanish ?
Zura Rozier
Registered User
Join date: 9 Mar 2007
Posts: 2
03-13-2007 21:19
Wow... <shakes the cobwebs out> ... it has been a while, thanks for the help folks, it works beautifully now )

and thanks for the reminder on the php tags... that one was burried in the dust too lol

Z