|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
04-01-2007 19:37
Here is the code. I'm hanging my head in shame. The code works fine with a "while" statement and will play until the song is over. All I am trying to do is get the bloody thing to let me drop the menu down with a stop option. Or just click the item itself and get it to stop even. I just can't seem to grasp the concept I guess and I cannot see why the below script doesn't work. It makes logical sense to me, however it now makes no sound at all, unless I change it back to a while statement rather than if. Thank you for taking time out for me. integer first_track; integer last_track; integer track; float sleep;
default { state_entry() { llListen(14145234,"","",""); } touch_start(integer num) { llDialog(llDetectedKey(0),"Play which song?",["Hobbit","Morrison's Jig","Ghandalf Falls","Surprise","STOP"],14145234); }
listen(integer channel, string name, key id, string message) { if (message == "Hobbit") {first_track = 3; last_track = 8; sleep=6.8;} if (message == "Morrison's Jig") {first_track = 15; last_track = 27; sleep=6.75;} if (message == "Ghandalf Falls") {first_track = 9; last_track = 14; sleep=6.8;} if (message == "Surprise") {first_track = 0; last_track = 2; sleep=6.8;} if (message == "STOP") {first_track = 10; last_track = 0; sleep=0.0;} track=first_track;
// starting here, if you change the 'if' to 'while' and take out the 'else' statement. It works. // However there is no way to stop the music either.
if (track<=last_track){ llPlaySound(llGetInventoryName(INVENTORY_SOUND, track), 10); llSleep(sleep); llPreloadSound(llGetInventoryName(INVENTORY_SOUND, track + 1)); track++; } else{ llStopSound(); llResetScript(); } } }
|
|
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
|
04-01-2007 20:26
My first thought looking through the way you did this, if you controlled the plays with a timer rather than a loop (and sleep), you would have the opportunity to react to other events such as a listen. So, you would set the timer to go off after "sleep" time and use *it* to play the next piece.
Hope that'll get you on the right track . . .
Baron
|
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
04-01-2007 20:44
From: Baron Hauptmann My first thought looking through the way you did this, if you controlled the plays with a timer rather than a loop (and sleep), you would have the opportunity to react to other events such as a listen. So, you would set the timer to go off after "sleep" time and use *it* to play the next piece. Hope that'll get you on the right track . . . Baron Great pointer. The unfortunate fact is that while our LSL code is busy doing anything (and especially during an llSleep call), it cannot respond to any events. That is precisely what I would do, switch to timers instead.
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
04-01-2007 21:28
Okay.. well I've not used timer events much at all because they confuse the heck out of me... seems like every time I try to use them.. I get a different result. I will do my best and see what happens. Thanks for the input. I'll see what I get.  Take care.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
04-01-2007 23:27
we breifly talked about this but for everyone else integer listen_channel; integer listener; integer first_track; integer last_track; integer track; float sleep;
play_track() { llOwnerSay("playing"); //llPlaySound(llGetInventoryName(INVENTORY_SOUND, track), 10); llSetTimerEvent(sleep); llOwnerSay("loading"); //llPreloadSound(llGetInventoryName(INVENTORY_SOUND, track + 1)); ++first_track; }
default { touch_start(integer total_number) { // if channel == 0 assign a new channel if (! listen_channel) listen_channel = llFloor(llFrand(-1000000.0)); //moving on listener =llListen(listen_channel,"","",""); llDialog( llDetectedKey(0), // USER ID "Play which song?", // MESSAGE TXT [ // OPTIONS LIST "Hobbit", "Morrison's Jig", "Ghandalf Falls", "Surprise", "STOP" ], // END LIST listen_channel // CHAT CHANNEL ); } listen(integer channel, string name, key id, string message) { if (message == "Hobbit") {first_track = 03; last_track = 08; sleep = 6.80;} else if (message == "Morrison's Jig") {first_track = 15; last_track = 27; sleep = 6.75;} else if (message == "Ghandalf Falls") {first_track = 09; last_track = 14; sleep = 6.80;} else if (message == "Surprise") {first_track = 00; last_track = 02; sleep = 6.80;} else if (message == "STOP") {first_track = 10; last_track = 00; sleep = 0.00;} play_track(); } timer() { if (first_track <= last_track) play_track(); else { llOwnerSay("stoping sound"); //llStopSound(); llSetTimerEvent(0); listen_channel = 0; llListenRemove(listener); } } }
|