Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Touch to Start/Stop

Grace Loudon
Registered Know-it-All
Join date: 16 Dec 2005
Posts: 99
04-29-2008 06:06
This may be the world's simplest script but I, scripting novice that I am, cannot figure it out to save my life.

I just want to start an object spinning by touching...got that part - easy breezy. Then touch it again to stop it. Stopping is the part I can't figure out. Anybody feeling kind and generous and willing to give a girl a hand? (I'm making a teacup amusement park ride)....could also use some ferris wheel help if you're feeling REALLY generous.

Grace
ivan Supply
llPleaseDoNotCamp();
Join date: 30 Nov 2006
Posts: 246
04-29-2008 08:38
CODE

integer open = FALSE;


default
{

touch_start(integer total_number) {

if (open == FALSE) {
open = TRUE;
llSetRot(llEuler2Rot(<0, 0, PI_BY_TWO>) * llGetRot());
} else {
open = FALSE;
llSetRot(llEuler2Rot(<0, 0, -PI_BY_TWO>) * llGetRot());
}

}

}
CODE



u can use smt like this . this is smt like hmh....a door :)
but if u can play with llTargetOmega

like

llTargetOmega(<2.0,2.0,0.7>,TWO_PI,1.0);

replace llTargetOmega line with llSetRot lines

i dunno what for exactly u need but this can give u idea...
_____________________
Grace Loudon
Registered Know-it-All
Join date: 16 Dec 2005
Posts: 99
04-29-2008 11:25
Thank you Ivan....but let's pretend I don't know *anything* about scripts....now take the pretend part out:) I want something to spin around and around and around when I touch it. Then I want it to stop spinning when I touch it again. Not a door - a cylinder platform.
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
04-29-2008 11:32
From: ivan Supply
CODE

integer open = FALSE;


default
{

touch_start(integer total_number) {

if (open == FALSE) {
open = TRUE;
llTargetOmega(<0,0,1>, 1, .1);
} else {
open = FALSE;
TargetOmega(<0,0,0>, 0, 0);
}

}

}
CODE


Changed to make it spin constantly, and here's an explanation of the code:

llTargetOmega() will set it to rotating.

The first section (WIthin the <> brackets) tells it which axis to spin around. In my above example it is Z, which makes a box spin 'sideways' if not moved after rezzed.

Then is spinrate, radians per second..I always use 1, never used it for speed.

Then is gain, which is the strength of the spin, which is what I use to change the speed. For some reason it works.

When it checks if OPEN == True it's checking if it is open, and if not, it starts it spinning and says that it is now OPEN. If it is OPEN, then it will stop the spinning.

That way you get it to spin when touched if not already spinning, and to stop if already spinning.

Hoping this made sense, and I altered the code to spin it constantly instead of move it to open and closed like a door.
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
04-29-2008 13:09
From: Grace Loudon
This may be the world's simplest script


Try this method with states, the SIM friendly one...
CODE

// Dora Gustafson 2008-04-29

vector RotAxis = < 1.0, 0.0, 0.0 >;
float spinrate = 5.0;
float gain = 1.0;

default
{
state_entry()
{
llTargetOmega( ZERO_VECTOR, 0.0, gain ); // stop apin
llOwnerSay( "Touch to start" );
}

touch_start(integer num_detected)
{
if ( llDetectedKey(0) == llGetOwner() )
{
state turn;
}
}
}

state turn
{
state_entry()
{
llTargetOmega( RotAxis, spinrate, gain ); // start spin
llOwnerSay( "Touch to stop" );
}

touch_start(integer num_detected)
{
if ( llDetectedKey(0) == llGetOwner() )
{
state default;
}
}
}
_____________________
From Studio Dora
Grace Loudon
Registered Know-it-All
Join date: 16 Dec 2005
Posts: 99
04-29-2008 14:06
YAY!!!! I love you guys. It worked and now I am a very happy camper. Thank you!
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
04-29-2008 14:09
From: Dora Gustafson
Try this method with states, the SIM friendly one...

Is using states really more sim-friendly?

edit: I'd probably have done this, just because it's easier for me to read..
CODE

CODE

integer gSpinning = FALSE;
float SPIN_RATE = 2.0;

DoIt()
{
if (gSpinning)
llTargetOmega (<0.0, 0.0, 1.0>, SPIN_RATE, 1.0);
else
llTargetOmega (<0.0, 0.0, 1.0>, 0.0, 1.0);
}

default
{
state_entry()
{
DoIt();
}

touch_start(integer count)
{
gSpinning = !gSpinning;
DoIt();
}
}
CODE
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
04-29-2008 14:10
From: Dora Gustafson
Try this method with states, the SIM friendly one...

Are states more SIM friendly? Looking at that, it's a lot more code, and more states to transition in. I've been told to use variables instead of multiple states before because it would be better for the SIM, etc, and now hearing this gets me confused. Which is actually better for the SIM lag-wise?
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-29-2008 15:30
From: Keira Wells
Are states more SIM friendly? Looking at that, it's a lot more code, and more states to transition in. I've been told to use variables instead of multiple states before because it would be better for the SIM, etc, and now hearing this gets me confused. Which is actually better for the SIM lag-wise?

State changes do require some extra processing, such as executing 'state_exit' and 'state_entry' handlers, removing all the script's listens, etc. If the logic paths are pretty simple, you might consider using variables instead of multiple states. When scripts get big and/or the logic complicated--when behavior in different "states" really is very different--I'd say states are still a good thing. Readability and maintainability over performance any day in my book (and if state changes are relatively infrequent instead of happening multiple times a second anyway, there isn't likely to be a huge difference).
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
To the bone
04-30-2008 02:45
From: Meade Paravane

edit: I'd probably have done this, just because it's easier for me to read..

And now to the bone:
CODE

integer onOff;
default {
touch_start(integer num_detected) {
onOff= !onOff;
llTargetOmega( < 1.0, 0.0, 0.0 >, 1.0*onOff, 1.0 );
}
}
_____________________
From Studio Dora