I'm new with scripting... so please forgive me if my question is stupid. The task is simple, I want to click on a prime and it starts rotating endlessly and if I click on it again it stops. I also programmed a "listen" so I can start or stop the rotation by a command on the chat ("/10000 Starts" or "/10000 Stop"
. It works fine to start the rotation, but it doesn't work when I want to stop it. I use a "while(1)" loop, to fire the llSetRot() function and it looks like the events aren't captured during a while loop. Here is the script:
The formating of the code is ugly here, because of the narrow text window, but if you cut and paste it into a text window with around 135 chars width, it will display correctly.
// ************************************************************************************************************************** //
// TiGuy's Flare Controler V1.1 //
// //
// Programmer : TiGuy GoalPost //
// Initial release: February 2008 //
// //
// The script is very simple. On startup, it forces the rotating part of the flare to a "stopped" state. On touch, it //
// will start rotating the light beams. //
// //
// Possible improvements: //
// - The rotation should stops on touch. It's supposed to stop rotating if we touch it again, but it just doesn't work //
// and I don't have a clue why. 8-( //
// - When the flare stops rotating, the yellow light beam should fade out and disapear, and the light bulb should be turned//
// white or a very light yellow. I suspect that the visual effect would be great. //
// - It could be useful to implement a "locked" state in which only the owner can control the flare. //
// //
// ************************************************************************************************************************** //
// Global variables definitions
string gScriptVersion = "Flare Controler V1.1";
integer gCommandChatChannel = 10000; // The chat channel that will be used to pass commands to the flare
string gStartCommand = "Start"; // The keyword to say on the command chat channel to start the flare
string gStopCommand = "Stop"; // The keyword to say on the command chat channel to stop the flare
integer gPublicChatChannel = 0;
integer gRotationIncrement = 10; // How many degre of rotation in each increment when rotating the light beam
integer gForever = TRUE; // Used to force endless loop
// ***************************************************************************************************************************//
// DEFAULT STATE //
// ************************************************************************************************************************** //
// This is the default state, this piece of code will be executed on the startup of the script
default
{
// The state_entry event code is executed once, when the default state starts
// By default when we rez the flare or reset the script, the flare is forced in the "Stopped" state
state_entry()
{
llSay(gPublicChatChannel,gScriptVersion + " is starting"
;state Stopped;
}
}
// ***************************************************************************************************************************//
// STATE RUNNING //
// ************************************************************************************************************************** //
state Running
{
// the state_entry code is executed when the state "Running" starts
state_entry()
{
// Start listening on the command chat channel. If something is said on that channel, the "listen" event
// will be executed.
integer ListenHandle = llListen(gCommandChatChannel, "", llGetOwner(), gStopCommand);
llOwnerSay("Say " + gStopCommand + " on channel " + (string)gCommandChatChannel + " to stop the flare."
;llSetTouchText("Stop"
; // Set the text for the "touch" item of the pie menuvector DegreAngleOffset = <0,0,gRotationIncrement>; // Set the increment of the rotation
vector RadianAngleOffset = DegreAngleOffset*DEG_TO_RAD; // Convert the angle into radians
rotation RotationAngleOffset = llEuler2Rot(RadianAngleOffset); // Convert the angle into a quaternion (default SL rotation)
// rotate the light beam forever
while (gForever)
{
llSetRot(llGetRot()*RotationAngleOffset); // Rotate the light beam
llSleep(0.1);
}
}
// Usually this event should be triggered when an AVI touches the flare, and the script should jump to the "Stopped" state.
// For some reason it does't work.
touch_start(integer Number)
{
state Stopped;
}
// This event is triggered when the script receive a message on the command chat channel. We filter to receive
// only messages from the owner, and only if the message is the stop command. So if we get a message, we assume that
// we need to switch to the "Stopped" state.
listen(integer channel, string name, key id, string message )
{
state Stopped;
}
}
// ***************************************************************************************************************************//
// STATE STOPPED //
// ************************************************************************************************************************** //
state Stopped
{
state_entry()
{
// Start listening on the command chat channel. If something is said on that channel, the "listen" event
// will be executed.
integer ListenHandle = llListen(gCommandChatChannel, "", llGetOwner(), gStartCommand);
llOwnerSay("Say " + gStartCommand + " on channel " + (string)gCommandChatChannel + " to start the flare."
;llSetTouchText("Start"
; // Set the text for the "touch" item of the pie menu}
// while in the "Stopped" state, if an AVI touch the light beam, the script jump to the "Running" state and starts
// rotating.
touch_start(integer Number)
{
state Running;
}
// This event is triggered when the script receive a message on the command chat channel. We filter to receive
// only messages from the owner, and only if the message is the start command. So if we get a message, we assume that
// we need to switch to the "Running" state.
listen(integer channel, string name, key id, string message )
{
state Running;
}


) Of course, that's all predicated on the Forums surviving till then. See