From: Milli Santos
// Inter-object commands
string commandDerez = "derez";
// This is the channel the main vendor talks to rezzed models on
integer commChannel;
default {
state_entry() {
llTargetOmega(<0,0,1>,0.2,1.0);
}
on_rez(integer startParam) {
commChannel = startParam;
llListen(commChannel, "", NULL_KEY, commandDerez);
}
listen(integer channel, string name, key id, string message) {
llDie();
}
}
The key piece here is the llTargetOmega function. Looking this up in the LSLWiki (
http://lslwiki.com/lslwiki/wakka.php?wakka=lltargetomega ) gives us
llTargetOmega(vector axis, float spinrate, float gain)
what you need to do to rotate clockwise instead of anticlockwise is to negate the spinrate. therefore you are looking for
llTargetOmega(<0,0,1>, -0.2, 1.0);
From: Milli Santos
Also, while I'm here.. I'd like to make the object play music and have the rotation and music start and stop by touch. Can someone please tell me how to do that?
One possible way to do this is to use states and another would be to use an integer as a switch.
Firstly with a state switch you include the touch event in your code above and within the touch event you change state. In the second state, which I will call off_state, (though it would make more sense for the default to be the off state I thought that perhaps having the code resemble the original above as much as possible would help with understanding the changes made to the code) we have an llTargetOmega call with zero for spinrate (and will include a llStopSound too once we get around to that).
So here goes:
string commandDerez = "derez";
// This is the channel the main vendor talks to rezzed models on
integer commChannel;
default {
state_entry() {
llTargetOmega(<0,0,1>, -0.2, 1.0);
// llSound(string sound, float volume, integer queue, integer loop);
// or other suitable sound playing function
}
on_rez(integer startParam) {
commChannel = startParam;
llListen(commChannel, "", NULL_KEY, commandDerez);
}
listen(integer channel, string name, key id, string message) {
llDie();
}
touch_start(integer number_of_touches) {
state off_state; // switch states
}
}
state off_state {
state_entry() {
llTargetOmega(<0,0,0>, 0.0, 0.0);
llStopSound();
llListen(commChannel, "", NULL_KEY, commandDerez);
}
touch_start(integer number_of_touches) {
state default;
}
listen(integer channel, string name, key id, string message) {
llDie();
}
}
Now I also mentioned an integer switch, in this case you would initialise a global integer and when the touch event is triggered you change the integer from a 0 to 1 or 1 to 0, in LSL you can assign TRUE and FALSE in the place of 1 and 0, this makes it easier to read in most cases. With the variable changed we test it useing an if function, if variable is TRUE then we turn on otherwise (else) we turn off, and this would be represented by the following code:
integer spin_on = FALSE;
default
{
touch_start(integer total_number)
{
spin_on = !spin_on; // a clever way of changing a TRUE to FALSE or FALSE to TRUE, the ! operator known as NOT
if (spin_on == TRUE) // this line could be simplified to if (spin_on)
{
llTargetOmega(<0,0,1>, -0.2, 1.0);
// llSound(string sound, float volume, integer queue, integer loop);
}
else
{
llTargetOmega(<0,0,0>,0.0,0.0);
llStopSound();
}
}
}
for more information on sound functions see
http://www.lslwiki.com/lslwiki/wakka.php?wakka=soundHere ends the lesson of the day, hope it was helpful.