Jump to content

Help changing a script to activate on sit, please.


Carlo Ghoststar
 Share

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

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

Recommended Posts

If someone could please help me, I need help changing the activation of a script. The speed and direction of the script is correct, I would like to change it to activate when an avatar sits on the object instead of on touch. Any help is much appreciated.

default

{

    state_entry()

    {

        llSay(0, "Ready to for a spin!");

        state still;

    }

}

state still

{

    touch_start(integer total_number)

    {

        llTargetOmega(<0,0,-0.4>,PI,1.0);

        state rotating;

    }

}

state rotating

{

    touch_start(integer total_number)

    {

        llTargetOmega(<0,0,1>,0,1.0);

        state still;

    }

}

Link to comment
Share on other sites

default{    state_entry()    {                        // OPTIONNAL : default cursor mouse displayed  is the sit action        llSetClickAction(CLICK_ACTION_SIT);        // OPTIONNAL lltargetomega works differently with physics .         // We want to rotate without been affected by the gravity        if (llGetStatus(STATUS_PHYSICS))        {            llSetPhysicsMaterial( GRAVITY_MULTIPLIER , .0, .0, .0, .0);        }        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION); // defines the seat position and rotation        state still;    }}state still{    changed(integer change)    {        if (change & CHANGED_LINK)        {             key av = llAvatarOnSitTarget();            if (av) // evaluated as true if key is valid and not NULL_KEY            {                state rotating;            }        }    }    state_exit() // When we go from still to state rotating we do this stuff     {        llTargetOmega(<0,0,-0.4>,PI,1.0);    }    }state rotating{    changed(integer change)    {        if (change & CHANGED_LINK)        {             key av = llAvatarOnSitTarget();            if (av==NULL_KEY) // evaluated as true if key is valid and not NULL_KEY            {                                state still;            }        }    }    state_exit() // when we go from state rotating to state still we do this stuff    {        llTargetOmega(<0,0,1>,0,1.0);    }    }

 

I have wroten it in respecting your initial idea to use states

Nevertheless it could be written with less code . 

Link to comment
Share on other sites

 We use states in LSL when a script is supposed to behave one way in one set of circumstances and another way in another -- for example, when you've got a vehicle that travels on land, in the air and on water, you will want it to behave very differently depending on whether it's moving on land, flying or sailing.    While you wouldn't actually need different states for that -- you could write it as one single state -- in practice, having three states, on_land, on_water and in_air, would almost certainly be far easier  than checking, each time it received an input in the control event, what it was supposed to do when someone presses the foward arrow key.

However, in your example, you just want the object to start rotating when someone sits on it and to stop when no one is seated.   To my mind, the example you found makes something simple far more complicated than it need be.  All you want is a simple test in the changed event, something like this:

 

default{	state_entry()	{		llSitTarget(<0.0,0.0,0.5>,ZERO_ROTATION);		//need a sit target for the test in the changed event	}	changed(integer change)	{		if(change & CHANGED_LINK){			//fires when someone sits down or stands up			if(llAvatarOnSitTarget()){//someone's just sat down //
//start spinning
} else{//they've just stood up //
//stop spinning
} } }}

 

Link to comment
Share on other sites

Yeah, when I was starting out with LSL, states seemed to be a way to make a script more readable whenever there were different modes of operation, which might otherwise be managed with a global variable and a bunch of conditionals. The place they're really indispensible, however, is when the script sometimes needs to handle certain events and other times to not just ignore those events, but not even have a handler for them. For example, making the object untouchable by going into a state with no touch-related event handler.

More to the point of the thread, there are applications where setting llSitTarget() may not be desirable. Seating multiple avatars on the same prim, for example. Or another script might be setting the sit target. Or there may be a bunch of child prim seats, and for the purposes of this script, we wouldn't want to run through them all, checking llAvatarOnLinkSitTarget(). For our purposes here, all that really matters is whether llGetNumberOfPrims() is greater than 1, and if so, whether the link at that index is an avatar.

Link to comment
Share on other sites

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