Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Reading one row at the time in a Notecard

Margot Schnyder
Generalsekretärin
Join date: 20 Feb 2007
Posts: 14
03-27-2007 06:45
Hi all... I'm trying to do a script that plays mp3s from my server with the help of a notecard, the info (and format of the info) i provide in the notcard is:
Human readable songtitle|mp3 filename|song duration in secconds

This allmost works, but the same line in the notecard get's repeated about 30 times, so ot feeds the same url 30 times in a row, with correct sleep time in between, and then it steps to the next line... I must confess that i have really hard time to understand the logics of how the dataserverthing works... I wich it would have been more like in php. :|

Does anyone knows where i think wrong or fail to think at all?

Code:
CODE
integer pointer=0;
string cardName="Songlist";
default
{
state_entry(){
}

touch_start(integer num)
{
llSay(0, "-=[ Starting Stereo V0.1a ]==-");
llGetNotecardLine(cardName, pointer);
}
dataserver(key id, string data)
{
if(pointer == 30){
pointer = 0;
llGetNotecardLine(cardName, pointer);
}
integer l = 30; // I tried to set this dynamically with llGetNumberOfNotecardLines("Songlist"), but that stepped the pointer on row forward. :(
integer s = 0;
while(s < l){
list songlist = llParseString2List(data,["|"],[""]);
llSay(0, "Playing " + llList2String(songlist,0));
llSetParcelMusicURL("http://mywebbserver.com/" + llList2String(songlist,1));
// llSay(0, "MP3 Name: " + llList2String(songlist, 1));
llSleep((integer)llList2String(songlist,2));
//llSay(0, "I should sleep for " + (string)llList2String(songlist,2) + "secconds.");
llGetNotecardLine(cardName, pointer);
s++;
pointer++;

}
}
}


Notecard "Songlist":
CODE
Alphaville - Big In Japan (03:53)|Alphaville_-_Big_In_Japan.mp3|233
Alphaville - Forever Young (03:50)|Alphaville_-_Forever_Young.mp3|230
New Baccara - Moonlight Shadow (04:03)|Baccara_-_Moonlight_Shadow.mp3|243
New Baccara - Touch Me (05:12)|Baccara_-_Touch Me.mp3|312
Boney M - Belfast (03:28)|Boney_M_-_Belfast.mp3|208
Boney M - Daddy Cool (03:29)|Boney_M_-_Daddy_Cool.mp3|209
Boney M - Rasputin (04:26)|Boney_M_-_Rasputin.mp3|266
Boney M - Rivers Of Babylon (04:17)|Boney_M_-_Rivers_Of_Babylon.mp3|257
Boney M - Sunny (03:16)|Boney_M_-_Sunny.mp3|196
Boogie Nights Disco Funk (02:38)|Boogie_Nights_Disco_Funk.mp3|158
Dschinghis Khan - Dschingis Kahn (03:05)|Dschinghis_Khan_-_Dschingis_Kahn.mp3|185
Dschingis Kahn - Komm doch heim (04:18)|Dschingis_Kahn_-_Komm_doch_heim.mp3|258
Dschingis Kahn - Moskau Moskau (06:01)|Dschingis_Kahn_-_Moskau,_Moskau.mp3|361
Electric Light Orchestra - Living Thing (03:31)|ELO_-_It's_A_Living_Thing.mp3|211
Eruption - One way ticket (03:35)|Eruption_-_One_way_ticket.mp3|215
Jane Birkin & Serge Gainsbourg - Jetaime (04:18)|Jetaime.mp3|258
John Paul Young - Love Is In The Air (03:23)|John_Paul_Young_-_Love_Is_In_The_Air.mp3|203
Karen Cheryl - Tchoo Tchoo (03:24)|Karen_Cheryl_-_Tchoo_Tchoo.mp3|204
Mono Fur Alle - Honecker Komm Zuruck (05:53)|Mono_Fur_Alle_-_Honecker_Komm_Zuruck.mp3|353
New Baccara - Caballero (03:59)|New_Baccara_-_Caballero.mp3|239
New Baccara - Fantasy Boy (05:32)|New_Baccara_-_Fantasy_Boy.mp3|332
Nina Hagen - Du hast den Farbfilm vergessen (03:04)|Nina_Hagen_-_Du_hast_den_Farbfilm_vergessen.mp3|184
Tommy Seebach - Apache (04:44)|Tommy_Seebach_-_Apache.mp3|284
Udo Lindenberg - Damals in der DDR (03:43)|Udo_Lindenberg_-_Damals_in_der_DDR.mp3|223
Veronica Unlimited - 06 - Daddy-O (03:46)|Veronica_Unlimited_-_06_-_Daddy-O.mp3|226
Veronica Unlimited - What Kind Of Dance Is This (03:36)|Veronica_Unlimited_-_What_Kind_Of_Dance_Is_This.mp3|216
Village People - Go west (03:31)|Village_People_-_Go_west.mp3|211
Village People - In The Navy (03:47)|Village_People_-_In_The_Navy.mp3|227
Village People - Macho Man (03:31)|Village_People_-_Macho_Man.mp3|211
Village People - You cant stop the music (03:39)|Village_People_-_You_cant_stop_the_music.mp3|219
_____________________
"Wir kennen nur ein Ziel, das die gesamte Politik unserer Partei durchdringt: alles zu tun für das Wohl des Menschen, für das Glück des Volkes, für die Interessen der Arbeiterklasse und aller Werktätigen. Das ist der Sinn des Sozialismus. Dafür arbeiten und kämpfen wir."
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-27-2007 07:12
Your while loop was forcing the same song to be repeated over and over.
LSL is a monotonic blocking system, no event handler can run while another event handler is in progress.

You are receiving the first touch fired request and then in side the event handler processing the same line 30 times hence playing the song thirty times.


CODE

integer pointer=0;
string cardName="Songlist";
key dataRequestID;

default
{
state_entry()
{
pointer = 0;
}

touch_start(integer num)
{
llSay(0, "-=[ Starting Stereo V0.1a ]==-");
state play;
}
}

state play
{
state_entry()
{
pointer = 0;
dataRequestID = llGetNotecardLine(cardName, pointer);
}

touch_start(integer num)
{
llSay(0, "-=[ Stoping Stereo V0.1a ]==-");
state default;
}

dataserver(key id, string data)
{
if(id == dataRequestID)
{
// If we have reached the end of the file , start again
if(data == EOF)
{
pointer = 0;
}
else
{
list songlist = llParseString2List(data,["|"],[""]);
string song = llList2String(songlist,0);
string file = llList2String(songlist,1);
integer time = llList2Integer(songlist,2);

// Inform the user
llSay(0, "Playing " + song);
llSetParcelMusicURL("http://mywebbserver.com/" + file);

llSleep(time);

// Increment the index
++pointer;
}
dataRequestID = llGetNotecardLine(cardName, pointer);
}
}
}
Margot Schnyder
Generalsekretärin
Join date: 20 Feb 2007
Posts: 14
03-27-2007 07:51
Wow! Many thanks Newgate! I never realized that LSL was monotonic, but that explains many of the other problems i have had to. :)

Your script works great... Many thanks! :)
_____________________
"Wir kennen nur ein Ziel, das die gesamte Politik unserer Partei durchdringt: alles zu tun für das Wohl des Menschen, für das Glück des Volkes, für die Interessen der Arbeiterklasse und aller Werktätigen. Das ist der Sinn des Sozialismus. Dafür arbeiten und kämpfen wir."