User:Zai Lynch/Sandbox/LSL Goodies: Difference between revisions
m formatting |
m notcard reader script (uncommented) |
||
| Line 77: | Line 77: | ||
<div id="box"> | <div id="box"> | ||
== | == Basic Notecard-Reader == | ||
<div style="padding: 0.5em"> | <div style="padding: 0.5em"> | ||
script | This script reads notecards placed in the same prim as the script itself. | ||
<lsl> | |||
////////////////////////////////////////////////////// | |||
// // | |||
// Basic Notecard-Reader // | |||
// Released under // | |||
// Creative Commons Attribution-Share Alike 3.0 // | |||
// by Zai Lynch // | |||
// // | |||
////////////////////////////////////////////////////// | |||
// Constants | |||
integer CHANNEL = 2130214; | |||
list MENU = ["Forward", "Backward", "Load", "Play", "Stop", "Time"]; | |||
// Variables | |||
list gMenuNC; | |||
integer gLine = 0; | |||
integer gTime = 5; | |||
string gNC = ""; | |||
zlGenerateList() | |||
{ | |||
integer i; | |||
integer n = llGetInventoryNumber(INVENTORY_NOTECARD); | |||
string name; | |||
gMenuNC = []; | |||
if (n > 0) | |||
{ | |||
for (i=0; i<n; i++) | |||
{ | |||
name = llGetInventoryName(INVENTORY_NOTECARD, i); | |||
if (llStringLength(name) < 25) | |||
gMenuNC = gMenuNC + [name]; | |||
else | |||
{ | |||
llSay(0, "Name: "+name + " is to long."); | |||
llRemoveInventory(name); | |||
llSay(0, "Notecard removed."); | |||
} | |||
} | |||
} | |||
if (gNC == "") gNC=llGetInventoryName(INVENTORY_NOTECARD,0); | |||
} | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
zlGenerateList(); | |||
llListen(CHANNEL, "", llGetOwner(), ""); | |||
llListen(CHANNEL+1, "", llGetOwner(), ""); | |||
} | |||
on_rez(integer start_param) | |||
{ | |||
llResetScript(); | |||
} | |||
changed(integer change) | |||
{ | |||
if (change == CHANGED_INVENTORY) zlGenerateList(); | |||
} | |||
touch_start(integer num) | |||
{ | |||
if (llDetectedKey(0) == llGetOwner()) llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
} | |||
listen(integer cha, string name, key id, string msg) | |||
{ | |||
if (cha == CHANNEL) | |||
{ | |||
if (msg == "Stop") | |||
{ | |||
llSetTimerEvent(0); | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
} | |||
if (msg == "Play") | |||
{ | |||
llSetTimerEvent(gTime); | |||
llGetNotecardLine(gNC, gLine); | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
} | |||
if (msg == "Forward") | |||
{ | |||
gLine = gLine + 1; | |||
llGetNotecardLine(gNC, gLine); | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
llSetTimerEvent(0); | |||
} | |||
if ((msg == "Backward") && (gLine > 0)) | |||
{ | |||
gLine = gLine - 1; | |||
llGetNotecardLine(gNC, gLine); | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
llSetTimerEvent(0); | |||
} | |||
if (msg == "Load") | |||
llDialog(llGetOwner(), " ", gMenuNC, CHANNEL+1); | |||
if (msg == "Time") | |||
state listening; | |||
} | |||
if (cha == (CHANNEL+1)) | |||
{ | |||
gNC = msg; | |||
gLine = 0; | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
} | |||
} | |||
timer() | |||
{ | |||
gLine = gLine+1; | |||
llGetNotecardLine(gNC, gLine); | |||
} | |||
dataserver(key qid, string data) | |||
{ | |||
llSay(0, data); | |||
} | |||
state_exit() | |||
{ | |||
llSetTimerEvent(0); | |||
} | |||
} | |||
state listening | |||
{ | |||
state_entry() | |||
{ | |||
llSetTimerEvent(30); | |||
llListen(0, "", llGetOwner(), ""); | |||
llSay(0,"Please tell me the desired updatetime in seconds."); | |||
} | |||
listen(integer cha, string name, key id, string msg) | |||
{ | |||
gTime = (integer)msg; | |||
llSay(0, "Time set."); | |||
state default; | |||
} | |||
timer() | |||
{ | |||
llSay(0,"Sorry, the request timed out."); | |||
state default; | |||
} | |||
state_exit() | |||
{ | |||
llSetTimerEvent(0); | |||
llDialog(llGetOwner()," ",MENU,CHANNEL); | |||
} | |||
} | |||
</lsl> | |||
</div></div> | </div></div> | ||
Revision as of 17:38, 28 May 2008
IntroSo just for the record: I'm a complete LSL n00b. So don't expect much from this page. 'Cause I love the Open Source concept, I'd like to share some of my scripts with other SL Residents =)
Simple CountdownThis script displays a hovering countdown above the item it's placed in.
llSetText(TEXT+"\n"+(string)(SECONDS/86400)+" days, "
+(string)((SECONDS%86400)/3600)+" hours, "
+(string)(((SECONDS%86400)%3600)/60)+" minutes, "
+(string)(((SECONDS%86400)%3600)%60)+ "seconds.",COLOR,1);
}
default { state_entry()
{
SECONDS = SECONDS + MINUTES * 60 + HOURS * 3600 + DAYS * 86400;
llSetTimerEvent(1);
countdown();
}
timer()
{
if (SECONDS > 0)
{
SECONDS = SECONDS - 1;
countdown();
}
else
{
llSetText(FINISHED, COLOR,1);
llSetTimerEvent(0);
}
}
} </lsl>
Basic Notecard-ReaderThis script reads notecards placed in the same prim as the script itself. <lsl> ////////////////////////////////////////////////////// // // // Basic Notecard-Reader // // Released under // // Creative Commons Attribution-Share Alike 3.0 // // by Zai Lynch // // // //////////////////////////////////////////////////////
integer CHANNEL = 2130214; list MENU = ["Forward", "Backward", "Load", "Play", "Stop", "Time"]; // Variables list gMenuNC; integer gLine = 0; integer gTime = 5; string gNC = "";
integer i;
integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
string name;
gMenuNC = [];
if (n > 0)
{
for (i=0; i<n; i++)
{
name = llGetInventoryName(INVENTORY_NOTECARD, i);
if (llStringLength(name) < 25)
gMenuNC = gMenuNC + [name];
else
{
llSay(0, "Name: "+name + " is to long.");
llRemoveInventory(name);
llSay(0, "Notecard removed.");
}
}
}
if (gNC == "") gNC=llGetInventoryName(INVENTORY_NOTECARD,0);
}
default { state_entry()
{
zlGenerateList();
llListen(CHANNEL, "", llGetOwner(), "");
llListen(CHANNEL+1, "", llGetOwner(), "");
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if (change == CHANGED_INVENTORY) zlGenerateList();
}
touch_start(integer num)
{
if (llDetectedKey(0) == llGetOwner()) llDialog(llGetOwner()," ",MENU,CHANNEL);
}
listen(integer cha, string name, key id, string msg)
{
if (cha == CHANNEL)
{
if (msg == "Stop")
{
llSetTimerEvent(0);
llDialog(llGetOwner()," ",MENU,CHANNEL);
}
if (msg == "Play")
{
llSetTimerEvent(gTime);
llGetNotecardLine(gNC, gLine);
llDialog(llGetOwner()," ",MENU,CHANNEL);
}
if (msg == "Forward")
{
gLine = gLine + 1;
llGetNotecardLine(gNC, gLine);
llDialog(llGetOwner()," ",MENU,CHANNEL);
llSetTimerEvent(0);
}
if ((msg == "Backward") && (gLine > 0))
{
gLine = gLine - 1;
llGetNotecardLine(gNC, gLine);
llDialog(llGetOwner()," ",MENU,CHANNEL);
llSetTimerEvent(0);
}
if (msg == "Load")
llDialog(llGetOwner(), " ", gMenuNC, CHANNEL+1);
if (msg == "Time")
state listening;
}
if (cha == (CHANNEL+1))
{
gNC = msg;
gLine = 0;
llDialog(llGetOwner()," ",MENU,CHANNEL);
}
}
timer()
{
gLine = gLine+1;
llGetNotecardLine(gNC, gLine);
}
dataserver(key qid, string data)
{
llSay(0, data);
}
state_exit()
{
llSetTimerEvent(0);
}
} state listening { state_entry()
{
llSetTimerEvent(30);
llListen(0, "", llGetOwner(), "");
llSay(0,"Please tell me the desired updatetime in seconds.");
}
listen(integer cha, string name, key id, string msg)
{
gTime = (integer)msg;
llSay(0, "Time set.");
state default;
}
timer()
{
llSay(0,"Sorry, the request timed out.");
state default;
}
state_exit()
{
llSetTimerEvent(0);
llDialog(llGetOwner()," ",MENU,CHANNEL);
}
} </lsl>
Script 3script
|
|