Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Stopping Sound in a chat activated script

Basement Desade
Registered User
Join date: 14 Jul 2006
Posts: 91
07-19-2008 16:22
Okay, so I am almost a complete tyro when it comes to scripting, though I have been learning a bit lately. This morning I went to the Autoscript page, and was very pleased that I was able to quickly create a couple of useful scripts. Simple ones, yes, but useful to me nonetheless.

Then, I decided to have it create a script that would play a sound loop when given a chat command. I got this:

CODE
default
{

state_entry() {
llListen(3,"", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message) {
if (message == "Engine on") {

llLoopSound(llGetInventoryName(INVENTORY_SOUND,0),1);

}
}

}
CODE


Okay, fine, that worked. I gave the command, and the sound started. So far so good. After a couple of minutes, however, it occurred to me that I needed a way to STOP the sound. So after a lot of tries, a lot of syntax errors, and a few bad words, I came up with this:

CODE
default
{

state_entry() {
llListen(3,"", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message) {
if (message == "Engine on")
{llLoopSound(llGetInventoryName(INVENTORY_SOUND,0),1);

if (message == "Engine off")
{llStopSound();}

}
}

}


"Yay, it finally compiled!" I thought. I saved and closed it, and with great anticipation gave the stop command. It ignored me. I made sure the script was set to running, then reset it. It pretended I didn't exist.

Sooo, I went and looked at the wiki regarding the llStopSound command. All I could find was a definition of the command, and on another page there was an example of how NOT to do it, but with no discussion of how TO do it. When I went to the discussion page, it invited me to write about it myself. Yeah, right. :P

So, you see, I am not merely trying to take the lazy way out. I HAVE done some research. To an experienced scripter, I am sure the solution to my problem is glaringly obvious. Anyone care to enlighten me? :)
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
07-19-2008 16:26
Make sure you're capitalizing correctly. As it is you need to say exactly 'Engine off' for it to work.

If you want it to work with any caps version, then use if(llToLower(message)=="engine off";)
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Basement Desade
Registered User
Join date: 14 Jul 2006
Posts: 91
07-19-2008 16:29
Thanks, Keira, but my problem is my scripting, not my typing. :) In fact, the reason I wanted this to start with chat is that I have another script that gives the command in chat. But, either way, by script or by typing, (correctly) it won't stop.
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
07-19-2008 16:34
It appears you didn't close the brackets after the loop sound line, ending that if, so you continued it for if the message is 'Engine on' and then ALSO if message is 'Engine off', which won't work.
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Basement Desade
Registered User
Join date: 14 Jul 2006
Posts: 91
07-19-2008 16:42
Hey! That's got it! Thanks SOOO much! :)

See, I knew it was something obvious. I'll get better at this, though, with practice.
Now I know that much, at least.:)
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
07-19-2008 16:49
From: Basement Desade
Hey! That's got it! Thanks SOOO much! :)

See, I knew it was something obvious. I'll get better at this, though, with practice.
Now I know that much, at least.:)

Glad it's fixed ^-^

Have fun, and good luck with all your endeavors :D
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL