Jump to content

ainst Composer
 Share

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

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

Recommended Posts

8 minutes ago, Fenix Eldritch said:

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

 

and how to make the ball move only once up and down?

Link to comment
Share on other sites

That would require altering the loop logic you employ. Currently, you use a while loop, which can do what you want, but you must add additional commands to control the variables. I would suggest you consider using a for-loop instead, as I personally think it's a little easier to read in this situation.

Basically:

integer x = 0;
for(x=0; x <= 10; x++)	//this loop moves the ball up
{
	//put command to increment prim's local position here
	//put command for 0.1 sleep here
}
for(x=0; x <= 10; x++)	//this loop moves the ball down
{
	//put command to decrement prim's local position here
	//put command for 0.1 sleep here
}

 

  • Thanks 1
Link to comment
Share on other sites

@Fenix Eldritch

Wow thanks very much! thats a progress! Ok so heres what i got. Now i need to add timer and animation...

 

myFunction() {
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default {
    state_entry() {
        llOwnerSay("Let's call a user defind function!");
        myFunction();
        llOwnerSay("We did it!");
    }
}

 

Edited by ainst Composer
Link to comment
Share on other sites

@Fenix Eldritch @Rolig Loon

Hooray! progress! I only need to add animation!

myFunction() {
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default {
    state_entry() {
        llSetTimerEvent(10);
    }

    timer() {
        //
        llOwnerSay("Let's call a user defind function!");
        myFunction();
        llOwnerSay("We did it!");
    }
}

 

  • Like 2
Link to comment
Share on other sites

@Fenix Eldritch @Rolig Loon

Take a look please I messed up with animations and timers.

myFunction() {
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default {
    state_entry() {
        llSetTimerEvent(10);
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }

    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            llStartAnimation("animation");
            llOwnerSay("animation will end in 1 second");
            llSetTimerEvent(1.0);
        }
    }

    timer() {
        //
        //        llOwnerSay("Let's call a user defind function!");
        myFunction();
        //        llOwnerSay("We did it!");
        llSetTimerEvent(0.0);
        llStopAnimation("animation");
    }
}

 

Edited by ainst Composer
Link to comment
Share on other sites

Well, you only messed up if you didn't intend to make the timer speed up from a ten-second oscillation period to a one second period.  If you meant to keep the ball moving up and down at the same pace as before, don't fiddle with the timer.  Here's where you get into the common dilemma of how to run two timers in a script when LSL only allows you to run one.  Not very far into the sticky thread on Tips at the top of this forum, you'll find a discussion of the common ways to solve the dilemma.  It's a good set of tricks to know about.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Yeah, did you mean to put a llSleep(1.0); command there instead of llSetTimerEvent(1.0); ? In either case, they wouoldn't be necessary there...

Recall that as per my suggestion, you would be starting the animation at the beginning of myFunction(). That way the avatar animation and ball movement code is all contained within an easy to access package any time you want (such as via a timer).

So the proposed sequence would be

  1. Request permission to trigger animations
  2. when you get permission, call myFunction()
  3. start your 10 second timer
  4. in your myFunction(), you have the code to animate and move the ball for one throw-catch cycle
  5. in your timer event, simply call myFunction()

That should be it! Also, because the avatar animation doesn't loop, it will end by itself - so you don't need to manually call llStopAnimation() for it.

And definitely check out the thread Rolig linked - some good stuff in there. :)

Edited by Fenix Eldritch
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

basically the same thing as above, but done with 1 loop

vector start;
bounceball()
{
    integer x;
    for(x = -10; x < 10; x++)
    {
        vector pos = start + <0,0,0.05*(llFabs(x)-10)>;
        llSay(0,(string)pos);
        llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_POS_LOCAL,pos]);
        llSleep(0.1);
    }
    llSetPos(start);
}
integer onoff;
default
{
    state_entry()
    {
        start = llGetLocalPos();
    }
    timer()
    {
        bounceball();
    }

    touch_start(integer total_number)
    {
        llSay(0,"boing");
        llSetTimerEvent(10*(onoff = !onoff));
        if(onoff)bounceball();
    }
}

 

  • Thanks 2
Link to comment
Share on other sites

@Fenix Eldritch @Rolig Loon @Ruthven Willenov

Hello! Thank you very much! almost everything is ready, just for some reason, the ball moves first and only after then the animation is triggered. Is it possible to synchronize them or at least somehow reduce the gap between ball movement and avatar animation? or swap them - first animation and then ball moving?

myFunction() {
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);


    
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default {
    state_entry() {
        llSetTimerEvent(10);
    }
    
        run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            llStartAnimation("backflip");

        }
    }

    timer() {
        //
//        llOwnerSay("Let's call a user defind function!");
        myFunction();
//        llOwnerSay("We did it!");
    }
}

3 seconds timer example:

ezgif.com-video-to-gif.gif

Edited by ainst Composer
  • Like 1
Link to comment
Share on other sites

This is because you're requesting permission to animate in the same function as the ball moving. The animation doesn't get triggered until the permissions event is triggered, but it can't do that until your function is finished....

You only need to request permissions once, then in your function, you can start the animation before moving the ball. Try this, i cleaned up your script a bit. If you still need a little more time before the ball moves after starting the animation, you'll need to put a sleep after triggering the animation

myFunction() 
{
    llStartAnimation("backflip");//start the animation before starting the ball moving
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default 
{
    on_rez(integer rez_param)
    {
        if(llGetAttached())//checks to see if it's attached instead of being rezzed onto ground
        {
            llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
        }
        else//if not attached, timer is turned off so the ball doesn't move
        {
            llSetTimerEvent(0);
        }
    }    
    
    run_time_permissions(integer perm) 
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION) 
        {
            llSetTimerEvent(3);//after we've got permission to play the animation, let's start the timer so the ball can bounce
        }
    }

    timer() 
    {
        myFunction();
    }
}

 

  • Thanks 2
Link to comment
Share on other sites

49 minutes ago, Ruthven Willenov said:

This is because you're requesting permission to animate in the same function as the ball moving. The animation doesn't get triggered until the permissions event is triggered, but it can't do that until your function is finished....

You only need to request permissions once, then in your function, you can start the animation before moving the ball. Try this, i cleaned up your script a bit. If you still need a little more time before the ball moves after starting the animation, you'll need to put a sleep after triggering the animation


myFunction() 
{
    llStartAnimation("backflip");//start the animation before starting the ball moving
    integer x = 0;
    for (x = 0; x <= 10; x++) //this loop moves the ball up
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, 0.05 > ]); //put command to increment prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
    for (x = 0; x <= 10; x++) //this loop moves the ball down
    {
        llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_POS_LOCAL, llGetLocalPos() + < 0, 0.0, -0.05 > ]); //put command to decrement prim's local position here
        llSleep(0.1); //put command for 0.1 sleep here
    }
}

default 
{
    on_rez(integer rez_param)
    {
        if(llGetAttached())//checks to see if it's attached instead of being rezzed onto ground
        {
            llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
        }
        else//if not attached, timer is turned off so the ball doesn't move
        {
            llSetTimerEvent(0);
        }
    }    
    
    run_time_permissions(integer perm) 
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION) 
        {
            llSetTimerEvent(3);//after we've got permission to play the animation, let's start the timer so the ball can bounce
        }
    }

    timer() 
    {
        myFunction();
    }
}

 

Thank you very very much! Its absolutely perfect!

  • Like 1
Link to comment
Share on other sites

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