Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 Good, that simplifies things then. you need only worry about starting the animation in time with the ball movement code and then restarting it after the timer pops. 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 1 minute ago, Fenix Eldritch said: Good, that simplifies things then. you need only worry about starting the animation in time with the ball movement code and then restarting it after the timer pops. I tried to add a timer but for some reason ball waits 10 seconds, and then moves up and down without stopping. integer vecpos = 0; default { state_entry() { // } touch_start(integer total_number) { llSetTimerEvent(10.0); } timer() { // while (vecpos <= 10) { if (vecpos < 10) { llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0, 0.05 > ]); vecpos++; llSleep(0.1); } else { while (vecpos != 0) { llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0, -0.05 > ]); vecpos--; llSleep(0.1); } } } } } Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 (edited) When you start a timer, the timer event doesn't get executed until the timer finishes counting down. So if you start a 10 second timer, the script will wait 10 seconds (not the same as sleeping) and then do the code in the timer event. After that it automatically resets its internal timer and starts counting down again - at which point it executes the timer event again. Lather rinse repeat. By putting your ball movement code in the timer event, it won't start until after the first 10 seconds have elapsed. Additionally, your movement code is what's called an infinite loop. It has no termination conditions, the while x <= 10 condition is always true. So the timer event never actually exits and will effectively hijack the script. There are a number of ways you can approach this, depending on what you want to do... If you want the overall object always animating the avatar and ball as long as its attached, then you can potentially forgo the timer and just start the animation at the beginning of the "throw ball up" loop. in this case, it's "okay" that the script loops infinitely, as it's intended to work as long as its attached. Although you'd probably need some changes to reset everything when you initially attach it. On the other hand, if you want to be able stop the object's animations without needing to detach the object completely, you'll need to restructure things a fair amount... It's not a huge problem, but the script's complexity does step up a bit. Edited February 6, 2019 by Fenix Eldritch 1 Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 4 minutes ago, Fenix Eldritch said: It is subjective to inbuilt function penalties. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 (edited) @Fenix Eldritch I removed the touch_start. that's what remains. but how to make it one throw every ten seconds? and how to embed animation there? integer vecpos = 0; default { state_entry() { llSetTimerEvent(10); } timer() { while (vecpos <= 10) { if (vecpos < 10) { llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); vecpos++; llSleep(0.1); } else { while (vecpos != 0) { llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); vecpos--; llSleep(0.1); } } } } } Edited February 6, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 Wait, are there two timing sequences in play here? Do you intend for the time it takes the ball to move up and down take ten seconds, or can that be shorter? Meaning is there some additional time between "catching" the ball before throwing it up again? I had assumed it was a constant throw-catch-throw-catch-etc.. sequence without a pause between. 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 3 minutes ago, Fenix Eldritch said: Wait, are there two timing sequences in play here? Do you intend for the time it takes the ball to move up and down take ten seconds, or can that be shorter? Meaning is there some additional time between "catching" the ball before throwing it up again? I had assumed it was a constant throw-catch-throw-catch-etc.. sequence without a pause between. yes one throw, the ball flies up and down, every 10 seconds. Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 5 minutes ago, ainst Composer said: yes one throw, the ball flies up and down, every 10 seconds. So as i suspected, it is an animation which is on a loop until deactivated. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 26 minutes ago, Fenix Eldritch said: Wait, are there two timing sequences in play here? Do you intend for the time it takes the ball to move up and down take ten seconds, or can that be shorter? Meaning is there some additional time between "catching" the ball before throwing it up again? I had assumed it was a constant throw-catch-throw-catch-etc.. sequence without a pause between. 14 minutes ago, steph Arnott said: So as i suspected, it is an animation which is on a loop until deactivated. in general, it looks like a script of eating or drinking only with a ball and the ball is moving Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 (edited) 3 minutes ago, ainst Composer said: in general, it looks like a script of eating or drinking only with a ball and the ball is moving So you have an animation of the avatar pose and the ball? Edited February 6, 2019 by steph Arnott Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 1 minute ago, steph Arnott said: So you have an animation of the avatar pose and the ball? yes animation of throwing/tossing and a ball Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 Just now, ainst Composer said: yes animation of throwing/tossing and a ball What about the avatar? Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 Just now, steph Arnott said: What about the avatar? ball is in avatars hand Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 Just now, ainst Composer said: ball is in avatars hand Avatar one animation, ball second animation. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 1 minute ago, steph Arnott said: Avatar one animation, ball second animation. Animation of avatar's throwing hand once a 10 seconds Ball is moving up and down once a 10 seconds Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 1 minute ago, ainst Composer said: Animation of avatar's throwing hand once a 10 seconds Ball is moving up and down once a 10 seconds Two animations. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 1 minute ago, steph Arnott said: Two animations. One animation. Ball movement. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 I found this example its very close to what i need. But I need to embed ball movement into it. //Emmas Seetan string animationToBePlayed = "drink"; integer flag; default { on_rez(integer start_param) { llResetScript(); } attach(key id) { // when being detached if(id == NULL_KEY) { integer currentPerms = llGetPermissions(); if (currentPerms & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(animationToBePlayed); } } changed(integer change) { if (change & (CHANGED_OWNER | CHANGED_INVENTORY)) { // stop animation for old owner integer currentPerms = llGetPermissions(); if (currentPerms & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(animationToBePlayed); // reset script to get new owner llResetScript(); } } state_entry() { key owner = llGetOwner(); llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION); } run_time_permissions(integer perm) { if(perm & PERMISSION_TRIGGER_ANIMATION) { llStartAnimation(animationToBePlayed); llSetTimerEvent(10.0); } } timer() { if(flag & 1) llStartAnimation(animationToBePlayed); flag = (flag + 1) % 4; } } Link to comment Share on other sites More sharing options...
steph Arnott Posted February 6, 2019 Share Posted February 6, 2019 1 minute ago, ainst Composer said: One animation. Ball movement. I wish you luck and hope it worksout for you. Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 (edited) 2 minutes ago, steph Arnott said: I wish you luck and hope it worksout for you. Thanks! you too! Edited February 6, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 So a recap of the conditions as I understand them: 1. Animate the avatar's hand with a short, non-looping hand movement 2. Initiate a loop in which the prim ball's position is moved in a series of short steps up, and then another series of short steps down, simulating the avatar tossing and catching it. 3. The time it takes the ball to traverse upwards and back down should take 10 seconds 4. Once the ball finishes the movement loop, it should start again from the beginning. If the above is accurate, then you could consider the following: It might be easier to create a custom function for a single throw-catch cycle. This function will start by setting the ball's start position. Then it will play the hand animation. Then it will stat the movement loop code. Change the loop to only execute once instead of forever. This way, you can call that custom function again for repeated throws. 1 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 (edited) 41 minutes ago, Fenix Eldritch said: So a recap of the conditions as I understand them: 1. Animate the avatar's hand with a short, non-looping hand movement 2. Initiate a loop in which the prim ball's position is moved in a series of short steps up, and then another series of short steps down, simulating the avatar tossing and catching it. 3. The time it takes the ball to traverse upwards and back down should take 10 seconds 4. Once the ball finishes the movement loop, it should start again from the beginning. If the above is accurate, then you could consider the following: It might be easier to create a custom function for a single throw-catch cycle. This function will start by setting the ball's start position. Then it will play the hand animation. Then it will stat the movement loop code. Change the loop to only execute once instead of forever. This way, you can call that custom function again for repeated throws. like this: Once every ten seconds, a timer is triggered. nonlooped one-second avatar animation is played - tossing the ball. for this second, the ball has time to fly up and down. everything repeats in every 10 seconds. in fact, the whole action lasts one second and repeats every 10 seconds. but of course i can make special 10 seconds animation with throwing/catching action on first or last second... but still the ball movement up/down will take only one second. 10 seconds pass between each toss and nothing happens. Edited February 6, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 (edited) 6 minutes ago, ainst Composer said: in fact, the whole action lasts one second and repeats every 10 seconds. That was my confusion earlier. Okay, even so, that doesn't change things all that much. I would still recommend you create a custom function for a single throw-catch cycle (which includes playing the hand animation at the start). Once all the permissions are established, you can call the function once, and then immediately start your 10-second timer. The timer event would just need to call that custom function as well. The effect should be that the catch-throw cycle will now occur every ten seconds when the timer pops. To make things easier as you're testing, include a touch_start event which calls your custom function when you click the object. After you get that working, you can remove it and replace it with the timer version. Edited February 6, 2019 by Fenix Eldritch 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted February 6, 2019 Author Share Posted February 6, 2019 (edited) 14 minutes ago, Fenix Eldritch said: That was my confusion earlier. Okay, even so, that doesn't change things all that much. I would still recommend you create a custom function for a single throw-catch cycle (which includes playing the hand animation at the start). Once all the permissions are established, you can call the function once, and then immediately start your 10-second timer. The timer event would just need to call that custom function as well. The effect should be that the catch-throw cycle will now occur every ten seconds when the timer pops. To make things easier as you're testing, include a touch_start event which calls your custom function when you click the object. After you get that working, you can remove it and replace it with the timer version. Thank you very much! I have absolutely no idea how to create a new function. Any tips? Yes, by the way, I announced a small reward for this script. in the section Wanted. Please help! Edited February 6, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted February 6, 2019 Share Posted February 6, 2019 They're quite simple, they look just like events, but exist outside the default state.They can be called like the normal LSL built-in functions. Here's a wiki page talking about them. This is what the framework might look like as simple example for you: myFunction() { llOwnerSay("user defined function was called!"); } default { state_entry() { llOwnerSay("Let's call a user defind function!"); myFunction(); llOwnerSay("We did it!"); } } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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