Fairealice Posted February 4, 2023 Share Posted February 4, 2023 Hello, Just to let you know i am new to creating. i made a rattle and i put a walking sound script on but i would like it to have a dialog box come up when touched so that i can turn the sound off and on with a button. can someone help me with that please? My dad and i looked everywhere. thank you Link to comment Share on other sites More sharing options...
Quistess Alpha Posted February 5, 2023 Share Posted February 5, 2023 string mySound; integer isOn; // script is 'active' integer isWalking; // owner is currently walking. key owner; default { state_entry() { mySound = llGetInventoryName(INVENTORY_SOUND,0); owner = llGetOwner(); } changed(integer c) { if(c&CHANGED_OWNER) { owner = llGetOwner(); } } touch_start(integer n) { isOn = !isOn; if(isOn) { llOwnerSay("Walking sound on."); llSetTimerEvent(0.5); }else { llOwnerSay("Walking sound off."); llSetTimerEvent(0.0); llStopSound(); } } timer() { integer walking = llGetAgentInfo(owner)&AGENT_WALKING; if(walking!=isWalking) { isWalking=walking; if(isWalking) { llLoopSound(mySound,1.0); }else { llStopSound(); } } } } If all you're doing is turning it off and on again, why do you need a dialog box? 1 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 5, 2023 Share Posted February 5, 2023 (edited) If all you want to do is turn the sound on and off, you don't really need a dialog box at all. All you need is a simple toggle switch that is touch-activated. The basics of a toggle switch are easy. You need a global integer variable that you can switch between TRUE and FALSE and you need a tiny bit of logic: integer iON; default { touch_start(integer num) { iON = !iON; // That is, reverse the sense of iON if (iON) { llLoopSound(my_sound, 1.0); } else { llStopSound(); } } } That's the toggle switch. Now, you'll want to transfer that logic into the script you already have, which is slightly more complicated because it has its own logic to turn the sound on and off depending on whether you are walking. If you look at your own script, you'll probably find its switching logic in a timer event that is watching llGetAgentInfo to see whether AGENT_WALKING is TRUE or not. So, see if you can figure out how to take everything from my touch_start event above except the line that says iON = !iON (the switch itself) and put it in that timer event to make the sound play only if iON is TRUE and you are walking. It's a nice beginning challenge. EDIT: Oh, darn. Tessa wrote the whole thing while I was typing mine, so you don't have the challenge any more. 😞 Well, now you see how it works. Edited February 5, 2023 by Rolig Loon 1 Link to comment Share on other sites More sharing options...
Fairealice Posted February 5, 2023 Author Share Posted February 5, 2023 Thank you so much ^^, oh right i'm not smart that's what my dad said to do but i think i was being stubborn XD But again thank you so much. 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 5, 2023 Share Posted February 5, 2023 Just now, Fairealice said: i think i was being stubborn XD There's nothing wrong with being stubborn. It keeps you from leaping to a conclusion without taking time to think things through for yourself. Scripting is more than just writing lines of code. It's basically about logic -- figuring out what you want to do and creating a map that tells your script where to make decisions. If you start writing code before you have at least a rough outline of your mental map, you'll just get frustrated. Be stubborn and poke at the logic until you have a pretty good idea what to do next. 2 Link to comment Share on other sites More sharing options...
Fairealice Posted February 5, 2023 Author Share Posted February 5, 2023 Thank you for your kind words i am new so i guess its gonna take time for me. Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now