Jump to content

ainst Composer
 Share

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

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

Recommended Posts

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

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 by Fenix Eldritch
  • Thanks 1
Link to comment
Share on other sites

@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 by ainst Composer
Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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

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

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

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 1
  • Thanks 1
Link to comment
Share on other sites

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 by ainst Composer
Link to comment
Share on other sites

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 by Fenix Eldritch
  • Thanks 1
Link to comment
Share on other sites

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 by ainst Composer
Link to comment
Share on other sites

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!");
    }
}

 

  • Thanks 1
Link to comment
Share on other sites

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