on touch, play a few animations in order?
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-04-2006 14:36
Hi, I'm a 3 week old newb in need of a pointer. In the script below the attach is working, the first animation is played, but the second animation (actually a 2 frame looping pose) isn't playing. I've triple-checked the name of the animation and it is as defined here. If you can spot where I'm going wrong here or suggest a better approach I'd very much appreciate it. After I get the below working, the plan is to add one more animation and one more pose, then llDetachFromAvatar Oh, and in my newbness I'll need an example of what you mean to go along with any english descriptions. Thanks! // // Cobbled together by Talthybius Brevity from various free and example // scripts // // Authors of original parts given credit where source known // // begin example attach script example from lslwiki.com
string gAnimName1 = "ani1"; // name the 1st animation string gAnimName2 = "ani2"; // name the 2nd animation
default { touch_start(integer num_detected) { // Ask the AV who touched me for permission to attach llRequestPermissions(llDetectedKey(0), PERMISSION_ATTACH); } run_time_permissions(integer perm) { if (perm & PERMISSION_ATTACH) { llAttachToAvatar(ATTACH_LHAND); // Do so } state playani1; } } // Basic Animation / Attachment 1.0 // Catherine Omega Heavy Industries
state playani1 {
state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); // ask the owner for permission to trigger animations llStartAnimation(gAnimName1); // automatically trigger animation. } on_rez(integer param) { llResetScript(); // reset the script as soon as it starts. } attach(key id) { integer perm = llGetPermissions(); if (id != NULL_KEY) // make sure we're actually attached. { if (! (perm & PERMISSION_TRIGGER_ANIMATION)) // remember to use bitwise operators! { llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); // request permissions from the owner. } } else { if (perm & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation(gAnimName1); // stop the animation } } state playpose1; } }
// repeat of Basic Animation / Attachment 1.0 // Catherine Omega Heavy Industries
state playpose1 {
state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); // ask the owner for permission to trigger animations llStartAnimation(gAnimName2); // automatically trigger animation. } on_rez(integer param) { llResetScript(); // reset the script as soon as it starts. } attach(key id) { integer perm = llGetPermissions(); if (id != NULL_KEY) // make sure we're actually attached. { if (! (perm & PERMISSION_TRIGGER_ANIMATION)) // remember to use bitwise operators! { llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); // request permissions from the owner. } } else { if (perm & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation(gAnimName2); // stop the animation } } } }
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
12-04-2006 16:50
OK, so you successfully attach, and go to state playan1. You said it's working till there, which I assume is because you see the first anim playing. So far so good. Now to move to the next state, it looks like it only happens in an attach handler in that state, and if id is NULL_KEY. So... that means you're waiting till the user detaches the object, and then you'll go to the next state. Is that how this is supposed to work? From your initial description, it sounded like you just wanted the animations played in sequence? If you want to do that, you'll need to find out how long the animations are (unfortunately there's no way to extract that information from the animation itself), and then try something like: llStartAnimation(anim1); llSleep(delay1);
llStopAnimation(anim1); llStartAnimation(anim2); llSleep(delay2);
...
You can do all of that in the state_entry of your anim1 state, I think. If that's not how you intended this to work.. you'll have to explain what you want in more detail  remember that the attach event handler is only called when the object is attached or detached. If it's already attached when you enter a state, it won't get called. In your case, you're calling Attach2Avatar, then changing state... that's interesting, because does the attach action happen while you're still in this state, or in the next state?  I also don't remember if event queues are flushed on state changes or not. So if there was an attach event pending while you were in the default state, and then you switch states, do you still get the attach event? I don't remember.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-04-2006 16:57
Thanks Ziggy! I think you've got me steered in the right direction. I'll give it a try tonight. 
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-04-2006 21:14
I'm getting a Syntax error at the left paren in the first appearance of (float What am i missing here?
string gAnimName1 = "anim1"; // name the 1st animation string gAnimName2 = "anim2"; // name the 2nd animation
default { touch_start(integer num_detected) { // Ask the AV who touched the object for permission to attach llRequestPermissions(llDetectedKey(0), PERMISSION_ATTACH); } run_time_permissions(integer perm) { if (perm & PERMISSION_ATTACH) { llAttachToAvatar(ATTACH_LHAND); // Do so } // end attach state startanim; } }
state startanim {
state_entry() { llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); // ask the owner for permission to trigger animations llStartAnimation(gAnimName1); llSleep(float 1.7);
llStopAnimation(gAnimName1); llStartAnimation(gAnimName2); llSleep(float 3); } on_rez(integer param) { llResetScript(); // reset the script as soon as it starts. } }
Thanks
|
|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
12-04-2006 21:17
From: Talthybius Brevity I'm getting a Syntax error at the left paren in the first appearance of (float
What am i missing here? You don't need the word "float" in those spots, just the number itself.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-04-2006 21:25
From: Anti Antonelli You don't need the word "float" in those spots, just the number itself. LOL What a silly n00b am i. Thanks Anti. That simple little fact is going to help make sense of a lot that has been perplexing me.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
Another idea
12-05-2006 04:59
Another approach. you could of course use a strided list instead. list Anims = ["anim1","anim2"]; list Times = [1.7,3.0];
default { touch_start(integer num_detected) { // Ask the AV who touched the object for permission to attach llRequestPermissions(llDetectedKey(0), PERMISSION_ATTACH); } run_time_permissions(integer perm) { if (perm & PERMISSION_ATTACH) { // Do so llAttachToAvatar(ATTACH_LHAND); } state startanim; } }
state startanim {
state_entry() { // ask the owner for permission to trigger animations llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); }
run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { integer len = llGetListLength(Anims); integer i = 0; while(i < len) { string animname = llList2String(Anims,i); float time = llList2Float(Times,i); llStartAnimation(animname); llSleep(time); llStopAnimation(animname); ++i; } } }
// reset the script if we rez in this state on_rez(integer param) { llResetScript(); } }
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-06-2006 00:07
Thanks very much Newgate. I'll give that a try if I run out of cheese. 
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-06-2006 15:02
I think I'm preferring your approach Newgate and I'm going to try it out tonight. Some changes to my process I want to ask for input on... It turns out need to change the order of events to be... On touch: 1) Play 1st animation 2) Play (and hold) 2nd animation (actually a pose) 3) Attach the object 4) Stop 2nd animation 5) Play 3rd animation 6) Play (and hold) 4th animation (actually a pose, sound needs to play with this one but my current thought is to tackle that after I've got the visuals working) 7) Play particle animation script (exists, working. can i drop it into this script or should it remain as a seperate script to be called by this one?) 9) Stop 4th animation 10) Detach object finis I see how I would add the additional animations to your great example script Newgate, but what I'm unsure of is the running 2 animations on touch, then switching to attach, then back to playing animations. Thanks! btw, the object is a bong. nothing new to SL, at least two others have done it quite well, but I have some designs that differ from what I've seen on their shelves. I've been getting very positive feedback on those designs, so it is worth a try.  Also, this will be but one type of product i'll be selling so i'm not going into direct competition with Foxy or Pyre[something-i-can't-recall] the anarchist. 
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-06-2006 16:06
I am not sure what you mean by 'hold' ? Do you mean loop until something else happens? You will be much better off going back to a set of discrete actions rather than using loops, although the lists can still be retained. I have no idea if the following will work or not but try this: // // On touch: // 1) Play 1st animation // // 2) Play (and hold) 2nd animation (actually a pose) // // 3) Attach the object // // 4) Stop 2nd animation // // 5) Play 3rd animation // // 6) Play (and hold) 4th animation (actually a pose, sound needs to play with this one but my current thought is to tackle that after I've got the visuals working) // // 7) Play particle animation script (exists, working. can i drop it into this script or should it remain as a seperate script to be called by this one?) // // 9) Stop 4th animation // // 10) Detach object
list Anims = ["anim1","anim2","anim3","anim4"]; list Times = [1.7,3.0,5.0,6.0]; string soundname = ""; float volume = 0.5; float particletimer = 10.0;
string animation;
ShowParticles() { }
StopParticles() { llParticleSystem([]); }
StopAnimation() { if(llStringLength(animation) > 0)llStopAnimation(animation); animation = ""; }
PlayAnimation(integer index) { StopAnimation(); animation = llList2String(Anims,index); float time = llList2Float(Times,index); llStartAnimation(animation); llSleep(time); }
default { state_entry() { }
touch_start(integer total_number) { // ask the owner for permission to trigger animations and to attach llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH); } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { PlayAnimation(0); PlayAnimation(1); if (perm & PERMISSION_ATTACH) llAttachToAvatar(ATTACH_LHAND); PlayAnimation(2); PlayAnimation(3); if(llStringLength(soundname) > 0)llPlaySound(soundname,volume); ShowParticles(); llSleep(particletimer); StopParticles(); StopAnimation(); llDetachFromAvatar(); } } }
Slot your particle code into the ShowParticles function, set the sound name and hopefully away you go!!
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-06-2006 16:13
From: Newgate Ludd I am not sure what you mean by 'hold' ? Do you mean loop until something else happens? Well, the animation is 2 frames, uploaded with the 'loop' toggled on, aka a pose, so it takes care of the looping. By hold i mean keep playing the animation/pose through out the attach action. This looks great. Thanks very much! I don't have a client installed on my work machine but i'll definitely be giving this a try tonight. Thanks again
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-06-2006 16:16
From: Talthybius Brevity Well, the animation is 2 frames, uploaded with the 'loop' toggled on, aka a pose, so it takes care of the looping. By hold i mean keep playing the animation/pose through out the attach action.
This looks great. Thanks very much! I don't have a client installed on my work machine but i'll definitely be giving this a try tonight.
Thanks again YW. You will of course need to tweak the timers, but hopefully even if it doesnt do exactly waht you want it may be close enough that you can use it as starting point.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-07-2006 02:25
So, I tweaked the timers, put in the real animation names, moved the sound up in the list, added a couple of animations and i'm off to the races! Newgate, would you accept 3% of my 3rd month of sales of objects with this script as a tiny token of my apprieciation? (I say 3rd month because it should be higher than the first month if things go well.  I can see from the number of views on the thread that I'm not the only person who is going to get some mileage from it! I ended up commenting out the particle stuff. I'd forgotten that the particle animation needs to come from a prim which isn't linked but is in the bong's contents and has to be attached separately to a different body part, then played. So I'm off to search the wiki and search this forum to figure out how to: - let multiple users use it (in succession) without it having to be re-rezzed or reset it. - 'drop' it instead of llDetachFromAvatar it - preload/precache the wav - the above mentioned second attach for the prim with the particle script in it. I've said this already but it bears saying again: Thanks Newgate!
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-07-2006 07:07
From: Talthybius Brevity So, I tweaked the timers, put in the real animation names, moved the sound up in the list, added a couple of animations and i'm off to the races! Newgate, would you accept 3% of my 3rd month of sales of objects with this script as a tiny token of my apprieciation? (I say 3rd month because it should be higher than the first month if things go well.  I can see from the number of views on the thread that I'm not the only person who is going to get some mileage from it! I ended up commenting out the particle stuff. I'd forgotten that the particle animation needs to come from a prim which isn't linked but is in the bong's contents and has to be attached separately to a different body part, then played. So I'm off to search the wiki and search this forum to figure out how to: - let multiple users use it (in succession) without it having to be re-rezzed or reset it. - 'drop' it instead of llDetachFromAvatar it - preload/precache the wav - the above mentioned second attach for the prim with the particle script in it. I've said this already but it bears saying again: Thanks Newgate! YW. I'll not turn down free cash but it is not required. As for you particles problem, how about rezzing the particle prim? have a single prim rez appropriately withthe particle, and possibly the sound script, in it and then die after x seconds? instead of calling ShowParticles or inside ShowParticles perform llRezObject("Particle Prim", llGetRootPos(), <0,0,0>, <0,0,0,0>, 0);
and away you go.... As for your other queries Not sure you can drop it rather than dettach. Reseting automatically isnt a problem, use llResetScript() Preloading a sound can be performed by using llPreloadSound(sound);
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-07-2006 10:44
You don't require the cash but I require giving it to you to maintain karmic balance.  But seriously, it's the least I can do. You've helped and taught me much. Rezzing the prim yes, forgot to mention, but the sticky part is getting it where it needs to be, which is attached to the AVs chin (it's a smoke exhale animation coming out of a small transparent prim.) I was digging through Jopsy's tutorial looking for a way to offset an animation in relation to the prim it is coming from but couldn't find one, which is what led me to the invisible prim on the chin idea. So i'm hoping to find a way to rez it then attach it. I've seen a similar script which upon detach the object goes back to where it was sitting when it was touch, which I was assuming was the equivalent of right-click --> drop, but maybe there's some other sort of magic happening there... And thanks for the extra tips!
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-07-2006 11:11
From: Talthybius Brevity You don't require the cash but I require giving it to you to maintain karmic balance.  But seriously, it's the least I can do. You've helped and taught me much. Rezzing the prim yes, forgot to mention, but the sticky part is getting it where it needs to be, which is attached to the AVs chin (it's a smoke exhale animation coming out of a small transparent prim.) I was digging through Jopsy's tutorial looking for a way to offset an animation in relation to the prim it is coming from but couldn't find one, which is what led me to the invisible prim on the chin idea. So i'm hoping to find a way to rez it then attach it. I've seen a similar script which upon detach the object goes back to where it was sitting when it was touch, which I was assuming was the equivalent of right-click --> drop, but maybe there's some other sort of magic happening there... And thanks for the extra tips! Well we are going into New-Newgy Territory here, I'm really not that advanced a scripter. Attaching the child prim to the AV's chin should be possible, although it may require that we request attach permissions for the new prim. The parent scipt can rez the prim, pass it a channel ID and then communicate the AV UUID (key) so that it can request permissions (if need) and then attach. Not tried it but I think it would work. Particles can be made to offset , at least visually, by playing with the various parameters. you have the PSYS_SRC_ANGLE_BEGIN, PSYS_SRC_ANGLE_END and PSYS_SRC_BURST_RADIUS paramters that probably cover it. Not sure about that last bit about dropping, you may find it deletes itself and a new one is then rerezzed but like I say this is new territory for me.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-07-2006 22:31
ahh, some helpful thoughts, thanks, I'll letcha know where I get to...
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-08-2006 02:20
Newgate your suggestion about rezzing the particle prim got me looking at http://www.lslwiki.com/lslwiki/wakka.php?wakka=llGetRootPositionIs what i'm reading there that I could rez a child prim a certain distance and location from the root prim? If so, can you show me what it would look like? i'm keep beating my head on it. thx!
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-08-2006 02:46
From: Talthybius Brevity Newgate your suggestion about rezzing the particle prim got me looking at http://www.lslwiki.com/lslwiki/wakka.php?wakka=llGetRootPositionIs what i'm reading there that I could rez a child prim a certain distance and location from the root prim? If so, can you show me what it would look like? i'm keep beating my head on it. thx! The function call llRezAtRoot will allow you to rez a prim relative to the root prim coordinates. In all other respects it works like llRezObject. I'm not 100% sure it will help much as the position of the chin will vary from AV to AV.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-08-2006 20:24
From: Newgate Ludd The function call llRezAtRoot will allow you to rez a prim relative to the root prim coordinates. In all other respects it works like llRezObject. I'm not 100% sure it will help much as the position of the chin will vary from AV to AV. well i'll certainly be playing with that tonight, thanks newg. the root prim will be attached to the Lhand, which will be held a few inches out from the Lpec, so i'm hoping that will mitigate things a big and let me get close enough for the desired effect.  once i've got the smoke prim attached properly i'm going to move the camera around to view the action. this is really fun stuff, i'm glad i'm in.
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-10-2006 00:20
From: Talthybius Brevity well i'll certainly be playing with that tonight, thanks newg. the root prim will be attached to the Lhand, which will be held a few inches out from the Lpec, so i'm hoping that will mitigate things a big and let me get close enough for the desired effect.  once i've got the smoke prim attached properly i'm going to move the camera around to view the action. this is really fun stuff, i'm glad i'm in. llRezAtRoot is working. w00t. odd thing. if someone clicks on it without first buying it, they and i both get the prompt for permissions. if i answer yes, i get animated. if they answer yes there is a permissions error. what can i do to allow people who don't own it to be animated by it?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-10-2006 03:59
From: Talthybius Brevity llRezAtRoot is working. w00t.
odd thing. if someone clicks on it without first buying it, they and i both get the prompt for permissions. if i answer yes, i get animated. if they answer yes there is a permissions error.
what can i do to allow people who don't own it to be animated by it? Well the current version is explicitly asking the owner, as it uses llGetOwner(). Change the touch_start to this touch_start(integer total_number) { key User = llDetectedKey(0); llRequestPermissions(User, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH); }
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-12-2006 16:27
From: Newgate Ludd Well the current version is explicitly asking the owner, as it uses llGetOwner(). Change the touch_start to this touch_start(integer total_number) { key User = llDetectedKey(0); llRequestPermissions(User, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH); }
Alas, non-owners get the dreaded "trying to attach to other than owner" message when they touch it. I've been digging in the forums and wiki but haven't seen note of anyone actually solving this or how they did, but I've seen it done with other similar products so it must be doable. Thoughts?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-13-2006 00:14
I dont think its allowed. ((Which is why i probably coded it as owner in the first place!))
|
|
Talthybius Brevity
Headshop Proprietor
Join date: 14 Nov 2006
Posts: 76
|
12-13-2006 00:20
From: Newgate Ludd I dont think its allowed. ((Which is why i probably coded it as owner in the first place!))  weird. i wonder what illusion i've seen at work to make it seem like it's happening. you can't temporarily give ownership and take it back can you?
|