Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Can't stop timer() !!

Pauski Zenovka
Registered User
Join date: 14 Mar 2007
Posts: 43
08-25-2007 14:02
Hi

I'm trying to put together a script that will aloow the suer to move through slides in a virewer either manually or by auto play (I know I can buy somthing t do this but I'm trying to learning scripting :) ).

It pretty much seems to work OK except that when you press next it goes into autplay mode - even if not set (it seems to default to 5 secs).

I'm obviusly doing something wrong or have something out of place but I'm afraid I can't see it.

Any help would be really appreciated (sorry the script is so long)

Thanks

Pauski

//-------------------------------------------------------------------------
//script:

string BLANK_TEXTURE = "5748decc-f629-461c-9a36-a35a221fe21f";
string slideName;
integer menu_handler;
integer menu_channel;
integer msg_channel = 0;
integer curSlide;
list slideTray;
integer autoPlayON = 0;

menu(key user,string title,list buttons)
{
menu_channel = (integer)(llFrand(99999.0) * -1);// reduce problems with more than 1 in range
menu_handler = llListen(menu_channel,"","","";);
llDialog(user,title,buttons,menu_channel);
llSetTimerEvent(5.0);
}

first() // move to the first slide in the tray
{
curSlide = 0;
slideName = llList2String(slideTray, curSlide);
llSetTexture(slideName,1);

}

last() //move to the last slide in the tray
{
curSlide = llGetListLength(slideTray) - 1;
slideName = llList2String(slideTray, curSlide);
llSetTexture(slideName,1);

}

back() //move back one slide
{
if (curSlide == 0)
{
curSlide = llGetListLength(slideTray) -1;
}
else
{
curSlide = curSlide -1;
}
slideName = llList2String(slideTray, curSlide);
llSetTexture(slideName,1);
}

next() //advance the viewer by one slide
{
if (curSlide == llGetListLength(slideTray) -1)
{
curSlide = 0;
}
else
{
curSlide = curSlide + 1;
}
slideName = llList2String(slideTray, curSlide);
llSetTexture(slideName,1);
}

reloadSlideTray() //reset and reload all slide textures. Reset current slide to first
{
slideTray = [];
curSlide = -1;
integer count = llGetInventoryNumber(INVENTORY_TEXTURE);
integer i;
for (i = 0; i < count; i++)
{
slideName = llGetInventoryName(INVENTORY_TEXTURE,i);
slideTray = slideTray + slideName;
}
slideName = llList2String(slideTray, curSlide);
llSetTexture(BLANK_TEXTURE,1);
llSay(0, "Slide tray reloaded. " + (string)llGetListLength(slideTray) + " slides loaded for use";);
next();
setAutoPlay(0);
}

setAutoPlay(float delay)
{
llSetTimerEvent(delay);
if (delay == 0)
{
llSay(msg_channel,"Auto play disabled";);
autoPlayON = 0;
}
else
{
llSay(msg_channel,"Auto play set to " + (string)delay + " seconds";);
autoPlayON = 1;
}
}

clearSlideTray()
{
integer i = 0;
integer n = llGetInventoryNumber(INVENTORY_TEXTURE);
while (n > i)
{
string name = llGetInventoryName(INVENTORY_TEXTURE, i);
llRemoveInventory(name);
n = llGetInventoryNumber(INVENTORY_TEXTURE);
}
curSlide = 0;
slideTray = [];
llSetTexture(BLANK_TEXTURE,1);
llSay(msg_channel,"All images have now been removed from the slide tray";);
setAutoPlay(0);
}

giveHelpSheet()
{
llSay(0,"PLease read the help sheet for more information";);
llGiveInventory(llDetectedKey(0),"HelpSheet";);
}


default
{
state_entry()
{
llSetColor(<0.2,0.2,0.2>, ALL_SIDES);
llSetTexture(BLANK_TEXTURE,1);
llSetColor(<1,1,1>, 1);
reloadSlideTray();
}

touch_start(integer total_number)
{
menu(llDetectedKey(0),"Remote Control",[ "|< FIRST", "RESET", "LAST >|", "<< BACK", "AUTO", "NEXT >>", "HELP"]);
}


timer()
{
llSay(0,"autoPlayON = " + (string)autoPlayON);
if (autoPlayON == 1 )
{
next();
}
}



listen(integer channel, string name, key id, string msg)
{
if (channel == menu_channel)
{
if (msg == "AUTO";)
{
llListenRemove(menu_handler);
menu(id,"Please select a delay between slides (in seconds)",["20", "25", "30", "5", "10", "15","AUTO OFF"]);
return;
}
if (msg == "<< BACK";)
{
back();
return;
}
if (msg == "NEXT >>";)
{
next();
return;
}

if (msg == "|< FIRST";)
{
first();
return;
}
if (msg == "LAST >|";)
{
last();
return;
}
if (msg == "RESET";)
{
llListenRemove(menu_handler);
menu(id,"Would like to clear your slides from the tray or reload the existing pslides?",["RELOAD","CLEAR"]);
return;
}
if (msg == "AUTO OFF";)
{
setAutoPlay(0);
return;
}
if (msg == "5";)
{
setAutoPlay(5);
return;
}
if (msg == "10";)
{
setAutoPlay(10);
return;
}
if (msg == "15";)
{
setAutoPlay(15);
return;
}
if (msg == "20";)
{
setAutoPlay(20);
return;
}
if (msg == "25";)
{
setAutoPlay(25);
return;
}
if (msg == "30";)
{
setAutoPlay(30);
return;
}
if (msg == "CLEAR";)
{
clearSlideTray();
return;
}

if (msg == "RELOAD";)
{
reloadSlideTray();
return;
}
if (msg == "HELP";)
{
giveHelpSheet();
return;
}

}
}




changed(integer change)
{
if ((change & CHANGED_INVENTORY) || (change & CHANGED_ALLOWED_DROP))
{
integer count = llGetInventoryNumber(INVENTORY_TEXTURE);
if (count > llGetListLength(slideTray)) // new slide added
{
reloadSlideTray();
}
}
}



}


//end of script
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
08-25-2007 14:16
It looks like whenever you call menu(), you set a 5 second timer. Could that be the reason?
Pauski Zenovka
Registered User
Join date: 14 Mar 2007
Posts: 43
08-25-2007 14:27
OK so now I'm hiding under the desk out of sheer shame...........

I knew it was simple and I knew I was just missing it - but that obvious!!

Many, many thanks for spotting it :))

Pauski