Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Controlled object

Shipper Sodwind
Registered User
Join date: 25 Nov 2006
Posts: 132
06-14-2008 07:12
I have a swing script, thanks to the forum, as well as a rotate script.
I am trying to control the start stop action via another scripted object, an on off switch.
I have manged to get the rotate one working

Rotate
CODE

default
{state_entry()
{llListen( -37641, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{if ( message == "Start" )
{llTargetOmega(<0,-1,0>, 0.3, 2);
}
else if ( message == "Stop" )
{llTargetOmega(<0,0,0>, 0.3, 2);
}
}
}
CODE


But no matter how much I try I cannot change the swing script to listen for the same command and remove the on touch start stop action. Any of that make sence?

This is the swing script;

CODE

float distance = 1.3;
float timetotake = 2.4;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;

startSwing()
{
vector vDir;

speed = distance / timetotake;
llSetTimerEvent(timetotake);
vDir = llRot2Up(llGetRot());
llSetRot(stoprot);
llTargetOmega( vDir, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
vector vDir = llRot2Up(llGetRot());

if( speed < 0 ) {
llSetRot(backrot);
} else {
llSetRot(forerot);
}
llTargetOmega( vDir, speed, 1.0 );
speed = 0 - speed;
}

integer swinging = 0;

default
{
on_rez(integer sp)
{
llResetScript();
}

state_entry()
{
rotation rrot = llGetRot();
vector vrot = llRot2Euler( rrot );
stoprot = rrot;
vrot.z += distance/2;
backrot = llEuler2Rot( vrot );
vrot.z -= distance;
forerot = llEuler2Rot( vrot );

llTargetOmega(<0,0,0>, 0, 0.0);
swinging = 0;

}

timer()
{
swingchange();
}

touch_start(integer total_number)
{
if( swinging > 0 ) {
swinging = 0;
llSetTimerEvent(0.0);
llTargetOmega(<0,0,0>, 0, 0.0 );
llSetRot(stoprot);
llTargetOmega(<0,0,0>, 0, 0.0 );
} else {
swinging = 1;
startSwing();
}
}

moving_end()
{
llSleep(2.0);
llResetScript();
}
}
CODE


Can somebody point me in the right direction?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
06-14-2008 08:31
Not sure I totally understand, but from what you have there, you're starting or stoping the rotation of the on/off switch, not the swing. If the switch hears the start or stop it should be doing an llSay to chat over to the swing to tell it to stop, although, you could just modify the swing script to listen for that. Personally, my swings start/stop automatically when the avatar sits/unsits the swing using llAvatarOnSitTarget(). Please clarify exactly what you're doing a bit, and what objects the scripts are going into.



http://www.secondscripter.com/
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Shipper Sodwind
Registered User
Join date: 25 Nov 2006
Posts: 132
06-14-2008 08:56
OK, three objects, a switch, a rotate by 360 object and a swing from side to side object.

The on off switch
CODE

integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
menu_channel = -37641 ;
menu_handler = llListen(menu_channel,"","","");
llDialog(user,title,buttons,menu_channel);
llSetTimerEvent(5.0);
}

default
{
touch_start(integer t)
{
menu(llDetectedKey(0),"Olni Mint by Shipper",["Start","Stop"]);
}
timer()
{
llSetTimerEvent(0.0);
llListenRemove(menu_handler);
}
listen(integer channel,string name,key id,string message)
{
if (channel == menu_channel)
{
llSetTimerEvent(0.0);
llListenRemove(menu_handler);
if(message == "Start")
{
llSay(menu_channel,"Start");
}
else if(message == "Stop")
{

}
}
}
}
CODE


Works fine

The 360 rotated prim
CODE

default
{state_entry()
{llListen( -37641, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{if ( message == "Start" )
{llTargetOmega(<0,-1,0>, 0.3, 2);
}
else if ( message == "Stop" )
{llTargetOmega(<0,0,0>, 0.3, 2);
}
}
}
CODE


Works fine on the switch and is controlled with the menu.

The swinging prim
CODE

float distance = 1.3;
float timetotake = 2.4;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;

startSwing()
{
vector vDir;

speed = distance / timetotake;
llSetTimerEvent(timetotake);
vDir = llRot2Up(llGetRot());
llSetRot(stoprot);
llTargetOmega( vDir, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
vector vDir = llRot2Up(llGetRot());

if( speed < 0 ) {
llSetRot(backrot);
} else {
llSetRot(forerot);
}
llTargetOmega( vDir, speed, 1.0 );
speed = 0 - speed;
}

integer swinging = 0;

default
{
on_rez(integer sp)
{
llResetScript();
}

state_entry()
{
rotation rrot = llGetRot();
vector vrot = llRot2Euler( rrot );
stoprot = rrot;
vrot.z += distance/2;
backrot = llEuler2Rot( vrot );
vrot.z -= distance;
forerot = llEuler2Rot( vrot );

llTargetOmega(<0,0,0>, 0, 0.0);
swinging = 0;

}

timer()
{
swingchange();
}

touch_start(integer total_number)
{
if( swinging > 0 ) {
swinging = 0;
llSetTimerEvent(0.0);
llTargetOmega(<0,0,0>, 0, 0.0 );
llSetRot(stoprot);
llTargetOmega(<0,0,0>, 0, 0.0 );
} else {
swinging = 1;
startSwing();
}
}

moving_end()
{
llSleep(2.0);
llResetScript();
}
}
CODE


Also needs to work on the same switch. But I cannot work out where to put the listener.

This is a machine, with many moving parts, some rotate and some swing. All to be controlled by the master on off switch.

Any help greatly apreciated.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-14-2008 11:21
The "360 rotated prim" script seems to have the answers. In the "swing" script too, llListen() would be called at the end of the state_entry() handler. And most of the code in the touch_start() handler would instead be in a listen() handler--keeping in mind that the "swinging" boolean isn't needed anymore because the message will tell whether to start or stop, as it does in the "rotated" script.
_____________________
Archived for Your Protection
Shipper Sodwind
Registered User
Join date: 25 Nov 2006
Posts: 132
06-14-2008 14:21
Yeah, thanks for that, but none the wiser.
Will try and go though what you said tomorrow.

Maybe this is a bit advanced for me