Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A touch of insanity.........

Valient Colville
Registered User
Join date: 1 Jul 2006
Posts: 4
04-18-2007 19:34
I would really appreciate some help with this script I'm writing. As its driving crazy why I can't get it to work correctly.

The touch command works fine to start the swing but will not stop it.

vector SwingPos;
integer i = 0;
rotation rot;
rotation delta;

default
{
state_entry()
{
llSetPos(llGetPos());
SwingPos = llGetPos();
}
touch_start(integer total_number)
{
state swing_start;
}
}

state swing_start
{
state_entry()
{

rot = llGetRot();
delta = llEuler2Rot(<0,-PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
state swing_forward;
}
touch_start(integer total_number)
{
state stopped;
}
}
state swing_forward
{
state_entry()
{
delta = llEuler2Rot(<0,PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
delta = llEuler2Rot(<0,-PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
state swing_back;
}
touch_start(integer total_number)
{
state stopped;
}
}
state swing_back
{
state_entry()
{
state swing_forward;
}
touch_start(integer total_number)
{
state stopped;
}
}
state stopped
{
state_entry()
{
llSetPos(SwingPos);
}
touch_start(integer total_number)
{
i = 0;
state swing_start;
}
}
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
04-18-2007 20:34
I think the problem is your script changes states so fast that it doesnt have the time to ponder if it got a touch or not. One solution would be to use a timer event:

CODE

vector SwingPos;
integer i = 0;
rotation rot;
rotation delta;
integer Swinging ;

integer SWING_STOP = 0 ;
integer SWING_START = 1 ;
integer SWING_FORWARD = 2 ;
integer SWING_BACK = 3 ;
swing_start()
{
rot = llGetRot();
delta = llEuler2Rot(<0,-PI/32,0>);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
Swinging = SWING_FORWARD ;
}

swing_forward()
{
delta = llEuler2Rot(<0,PI/32,0>);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
delta = llEuler2Rot(<0,-PI/32,0>);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
Swinging = SWING_BACK ;
}


swing_back()
{
Swinging = SWING_FORWARD ;
}

swing_stop()
{
llSetPos(SwingPos);
llSetTimerEvent(0.0) ;
}

default
{
state_entry()
{
llSetPos(llGetPos());
SwingPos = llGetPos();
Swinging = FALSE ;
}
touch_start(integer total_number)
{
if (Swinging != SWING_STOP) {
Swinging = SWING_STOP ;
}
else
{
llSetTimerEvent(0.1) ;
Swinging = SWING_START ;
}
}
timer()
{
if (Swinging == SWING_START)
swing_start() ;
if (Swinging == SWING_FORWARD)
swing_forward() ;
if (Swinging == SWING_BACK)
swing_back() ;
if (Swinging == SWING_STOP)
swing_stop() ;
}

}
Valient Colville
Registered User
Join date: 1 Jul 2006
Posts: 4
04-18-2007 20:39
I'll try that and see what i get ty
Valient Colville
Registered User
Join date: 1 Jul 2006
Posts: 4
that did stop it......
04-18-2007 21:08
Ok, I tried that and it does stop it but now it will not return to the right SetPos.
Valient Colville
Registered User
Join date: 1 Jul 2006
Posts: 4
woot it works......
04-18-2007 21:50
Thank you tons Twisted!!!

The problem was I used llSetPos but not llSetRot so it stopped at the end of a cycle and kept turning at the start to a new angle. I now returns to the correct rotation on stop and the touch commands are working perfectly.

You a life saver :)))

vector SwingPos;
rotation SwingRot;
integer i = 0;
rotation rot;
rotation delta;
integer Swinging ;

integer SWING_STOP = 0;
integer SWING_START = 1;
integer SWING_FORWARD = 2;
integer SWING_BACK = 3;
swing_start()
{
rot = llGetRot();
delta = llEuler2Rot(<0,-PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
Swinging = SWING_FORWARD;
}

swing_forward()
{
delta = llEuler2Rot(<0,PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
delta = llEuler2Rot(<0,-PI/32,0>;);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
rot = delta * rot;
llSetRot(rot);
Swinging = SWING_BACK;
}


swing_back()
{
Swinging = SWING_FORWARD;
}

swing_stop()
{
llSetPos(SwingPos);
llSetRot(SwingRot);
llSetTimerEvent(0.0);
}

default
{
state_entry()
{
llSetPos(llGetPos());
SwingPos = llGetPos();
SwingRot = llGetRot();
Swinging = FALSE ;
}
touch_start(integer total_number)
{
if (Swinging != SWING_STOP)
{
Swinging = SWING_STOP;
swing_stop();
}
else
{
llSetTimerEvent(0.1) ;
Swinging = SWING_START ;
}
}
timer()
{
if (Swinging == SWING_START)
swing_start() ;
if (Swinging == SWING_FORWARD)
swing_forward() ;
if (Swinging == SWING_BACK)
swing_back() ;
if (Swinging == SWING_STOP)
swing_stop() ;
}

}
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
04-18-2007 21:59
You're welcome. Cool script by the way :).