Difference between revisions of "Binary Clock v1.1"
Jump to navigation
Jump to search
Kireji Haiku (talk | contribs) m (some minor memory usage improvements) |
Omei Qunhua (talk | contribs) (Well, Strife suggested it needed abbreviating, LOL. Anyone care to check?) |
||
Line 1: | Line 1: | ||
{{LSL Header}} | {{LSL Header}} | ||
== Binary Clock V1. | == Binary Clock V1.2 == | ||
<lsl> | <lsl> | ||
// Binary Clock Script | // Binary Clock Script | ||
Line 13: | Line 13: | ||
string dec2bin(integer dec) | string dec2bin(integer dec) | ||
{ | { | ||
return llGetSubString("0000,0001,0010,0011,0100,0101,0110,0111,1000,1001", dec * 5, dec * 5 + 3); | |||
} | } | ||
Line 34: | Line 24: | ||
integer seconds = shiftraw % 60; | integer seconds = shiftraw % 60; | ||
bTime = [hours | bTime = [hours / 10, hours % 10, | ||
minutes / 10, minutes % 10, | |||
seconds / 10, seconds % 10]; | |||
} | |||
SendDigitsToLinks(string str, integer link, integer len) | |||
{ | |||
integer x = 3; | |||
while(len--) | |||
{ | |||
llMessageLinked(link++, (integer) llGetSubString(str, x, x) , "", ""); | |||
--x; | |||
} | |||
} | } | ||
Line 43: | Line 42: | ||
{ | { | ||
integer current_rowA = llList2Integer(bTime, 0); | integer current_rowA = llList2Integer(bTime, 0); | ||
if (current_rowA != llList2Integer(oTime, 0) ) | |||
{ | { | ||
string rowA = dec2bin(current_rowA); | string rowA = dec2bin(current_rowA); | ||
SendDigitsToLinks(rowA, 2, 2); | |||
} | } | ||
else if (!current_rowA) | |||
SendDigitsToLinks("00", 2, 2); | |||
integer current_rowB = llList2Integer(bTime, 1); | integer current_rowB = llList2Integer(bTime, 1); | ||
if (current_rowB != llList2Integer(oTime, 1)) | |||
{ | { | ||
string rowB = dec2bin(current_rowB); | string rowB = dec2bin(current_rowB); | ||
SendDigitsToLinks(rowB, 4, 4); | |||
} | } | ||
else if (!current_rowB) | else if (!current_rowB) | ||
SendDigitsToLinks("0000", 4, 4); | |||
integer current_rowC = llList2Integer(bTime, 2); | integer current_rowC = llList2Integer(bTime, 2); | ||
if (current_rowC != llList2Integer(oTime, 2)) | |||
{ | { | ||
string rowC = dec2bin(current_rowC); | string rowC = dec2bin(current_rowC); | ||
SendDigitsToLinks(rowC, 8, 3); | |||
} | } | ||
else if (!current_rowC) | else if (!current_rowC) | ||
SendDigitsToLinks("000", 8, 3); | |||
integer current_rowD = llList2Integer(bTime, 3); | integer current_rowD = llList2Integer(bTime, 3); | ||
if (current_rowD != llList2Integer(oTime, 3)) | |||
{ | { | ||
string rowD = dec2bin(current_rowD); | string rowD = dec2bin(current_rowD); | ||
SendDigitsToLinks(rowD, 11, 4); | |||
} | } | ||
else if (!current_rowD) | else if (!current_rowD) | ||
SendDigitsToLinks("0000", 11, 4); | |||
integer current_rowE = llList2Integer(bTime, 4); | integer current_rowE = llList2Integer(bTime, 4); | ||
if (current_rowE != llList2Integer(oTime, 4)) | |||
{ | { | ||
string rowE = dec2bin(current_rowE); | string rowE = dec2bin(current_rowE); | ||
SendDigitsToLinks(rowE, 15, 3); | |||
} | } | ||
else if (!current_rowE) | else if (!current_rowE) | ||
SendDigitsToLinks("000", 15, 3); | |||
integer current_rowF = llList2Integer(bTime, 5); | integer current_rowF = llList2Integer(bTime, 5); | ||
if (current_rowF != llList2Integer(oTime, 5)) | |||
{ | { | ||
string rowF = dec2bin(current_rowF); | string rowF = dec2bin(current_rowF); | ||
SendDigitsToLinks(rowF, 18, 4); | |||
} | } | ||
else if (!current_rowF) | else if (!current_rowF) | ||
SendDigitsToLinks("0000", 18, 4); | |||
} | } | ||
Line 179: | Line 105: | ||
touch_start(integer total_number) | touch_start(integer total_number) | ||
{ | { | ||
if (llDetectedKey(0) != llGetOwner() ) | |||
return; | return; | ||
if ( !(token = !token) ) | |||
if (token) | |||
llOwnerSay("Off!"); | llOwnerSay("Off!"); | ||
else | else | ||
{ | { | ||
oTime = | oTime = bTime = []; | ||
llOwnerSay("On!"); | llOwnerSay("On!"); | ||
} | } | ||
llSetTimerEvent(token); | |||
} | } | ||
Revision as of 12:34, 12 January 2013
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Binary Clock V1.2
<lsl> // Binary Clock Script // By Fox Diller // OMG INSANITY!
list bTime; list oTime;
integer token;
string dec2bin(integer dec) {
return llGetSubString("0000,0001,0010,0011,0100,0101,0110,0111,1000,1001", dec * 5, dec * 5 + 3);
}
BuildClock() {
integer shiftraw = (integer)llGetWallclock();
integer hours = shiftraw / 3600; integer minutes = (shiftraw % 3600) / 60; integer seconds = shiftraw % 60;
bTime = [hours / 10, hours % 10, minutes / 10, minutes % 10, seconds / 10, seconds % 10];
}
SendDigitsToLinks(string str, integer link, integer len) {
integer x = 3; while(len--) { llMessageLinked(link++, (integer) llGetSubString(str, x, x) , "", ""); --x; }
}
displayBDC() {
integer current_rowA = llList2Integer(bTime, 0); if (current_rowA != llList2Integer(oTime, 0) ) { string rowA = dec2bin(current_rowA); SendDigitsToLinks(rowA, 2, 2); } else if (!current_rowA) SendDigitsToLinks("00", 2, 2);
integer current_rowB = llList2Integer(bTime, 1); if (current_rowB != llList2Integer(oTime, 1)) { string rowB = dec2bin(current_rowB); SendDigitsToLinks(rowB, 4, 4); } else if (!current_rowB) SendDigitsToLinks("0000", 4, 4);
integer current_rowC = llList2Integer(bTime, 2); if (current_rowC != llList2Integer(oTime, 2)) { string rowC = dec2bin(current_rowC); SendDigitsToLinks(rowC, 8, 3); } else if (!current_rowC) SendDigitsToLinks("000", 8, 3);
integer current_rowD = llList2Integer(bTime, 3); if (current_rowD != llList2Integer(oTime, 3)) { string rowD = dec2bin(current_rowD); SendDigitsToLinks(rowD, 11, 4); } else if (!current_rowD) SendDigitsToLinks("0000", 11, 4);
integer current_rowE = llList2Integer(bTime, 4); if (current_rowE != llList2Integer(oTime, 4)) { string rowE = dec2bin(current_rowE); SendDigitsToLinks(rowE, 15, 3); } else if (!current_rowE) SendDigitsToLinks("000", 15, 3);
integer current_rowF = llList2Integer(bTime, 5); if (current_rowF != llList2Integer(oTime, 5)) { string rowF = dec2bin(current_rowF); SendDigitsToLinks(rowF, 18, 4); } else if (!current_rowF) SendDigitsToLinks("0000", 18, 4);
}
MessageLinked(integer inputLinkNumber, integer inputNumber) {
llMessageLinked(inputLinkNumber, inputNumber, "", "");
}
default {
touch_start(integer total_number) { if (llDetectedKey(0) != llGetOwner() ) return; if ( !(token = !token) ) llOwnerSay("Off!"); else { oTime = bTime = []; llOwnerSay("On!"); } llSetTimerEvent(token); }
timer() { bTime = oTime; BuildClock(); displayBDC(); }
} </lsl>