Difference between revisions of "Binary Clock v1.1"

From Second Life Wiki
Jump to navigation Jump to search
m (lsl code tagging)
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
== Binary Clock V1.1 ==
== Binary Clock V1.2 ==
<lsl>
<source lang="lsl2">
// Binary Clock Script
// Binary Clock Script
// By Fox Diller
// By Fox Diller
Line 13: Line 13:
string dec2bin(integer dec)
string dec2bin(integer dec)
{
{
     if (dec == 0) return "0000";
     return llGetSubString("0000,0001,0010,0011,0100,0101,0110,0111,1000,1001", dec * 5, dec * 5 + 3);
    if (dec == 1) return "0001";
    if (dec == 2) return "0010";
    if (dec == 3) return "0011";
    if (dec == 4) return "0100";
    if (dec == 5) return "0101";
    if (dec == 6) return "0110";
    if (dec == 7) return "0111";
    if (dec == 8) return "1000";
    if (dec == 9) return "1001";
    return "0000";
}
}


Line 29: Line 19:
{
{
     integer shiftraw = (integer)llGetWallclock();
     integer shiftraw = (integer)llGetWallclock();
   
 
     integer hours = shiftraw / 3600;
     integer hours = shiftraw / 3600;
     integer minutes = (shiftraw % 3600) / 60;
     integer minutes = (shiftraw % 3600) / 60;
     integer seconds = shiftraw % 60;
     integer seconds = shiftraw % 60;
   
 
     bTime = [hours   / 10, hours   % 10,
     bTime = [hours / 10, hours % 10,
            minutes / 10, minutes % 10,
        minutes / 10, minutes % 10,
            seconds / 10, seconds % 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);
     integer old_rowA = llList2Integer(oTime, 0);
     if (current_rowA != llList2Integer(oTime, 0) )
    if (current_rowA != old_rowA)
     {
     {
         string rowA = dec2bin(current_rowA);
         string rowA = dec2bin(current_rowA);
         integer Acol0 = (integer)llGetSubString(rowA, 3, 3);
         SendDigitsToLinks(rowA, 2, 2);
        integer Acol1 = (integer)llGetSubString(rowA, 2, 2);
        llMessageLinked(2, Acol0, "", "");
        llMessageLinked(3, Acol1, "", "");
    } else if (!current_rowA) {
        llMessageLinked(2, 0, "", "");
        llMessageLinked(3, 0, "", "");
     }
     }
      
     else if (!current_rowA)
        SendDigitsToLinks("00", 2, 2);
 
     integer current_rowB = llList2Integer(bTime, 1);
     integer current_rowB = llList2Integer(bTime, 1);
     integer old_rowB = llList2Integer(oTime, 1);
     if (current_rowB != llList2Integer(oTime, 1))
    if (current_rowB != old_rowB)
     {
     {
         string rowB = dec2bin(current_rowB);
         string rowB = dec2bin(current_rowB);
         integer Bcol0 = (integer)llGetSubString(rowB, 3, 3);
         SendDigitsToLinks(rowB, 4, 4);
        integer Bcol1 = (integer)llGetSubString(rowB, 2, 2);
        integer Bcol2 = (integer)llGetSubString(rowB, 1, 1);
        integer Bcol3 = (integer)llGetSubString(rowB, 0, 0);
        llMessageLinked(4, Bcol0, "", "");
        llMessageLinked(5, Bcol1, "", "");
        llMessageLinked(6, Bcol2, "", "");
        llMessageLinked(7, Bcol3, "", "");
    } else if (!current_rowB) {
        llMessageLinked(4, 0, "", "");
        llMessageLinked(5, 0, "", "");
        llMessageLinked(6, 0, "", "");
        llMessageLinked(7, 0, "", "");
     }
     }
          
    else if (!current_rowB)
               
         SendDigitsToLinks("0000", 4, 4);
 
     integer current_rowC = llList2Integer(bTime, 2);
     integer current_rowC = llList2Integer(bTime, 2);
     integer old_rowC = llList2Integer(oTime, 2);
     if (current_rowC != llList2Integer(oTime, 2))
    if (current_rowC != old_rowC)
     {
     {    
         string rowC = dec2bin(current_rowC);
         string rowC = dec2bin(current_rowC);
         integer Ccol0 = (integer)llGetSubString(rowC, 3, 3);
         SendDigitsToLinks(rowC, 8, 3);
        integer Ccol1 = (integer)llGetSubString(rowC, 2, 2);
        integer Ccol2 = (integer)llGetSubString(rowC, 1, 1);
        llMessageLinked(8, Ccol0, "", "");
        llMessageLinked(9, Ccol1, "", "");
        llMessageLinked(10, Ccol2, "", "");
    } else if (!current_rowC) {
        llMessageLinked(8, 0, "", "");
        llMessageLinked(9, 0, "", "");
        llMessageLinked(10, 0, "", "");
     }
     }
      
     else if (!current_rowC)
        SendDigitsToLinks("000", 8, 3);
 
     integer current_rowD = llList2Integer(bTime, 3);
     integer current_rowD = llList2Integer(bTime, 3);
     integer old_rowD = llList2Integer(oTime, 3);
     if (current_rowD != llList2Integer(oTime, 3))
    if (current_rowD != old_rowD)
     {
     {
         string rowD = dec2bin(current_rowD);
         string rowD = dec2bin(current_rowD);
         integer Dcol0 = (integer)llGetSubString(rowD, 3, 3);
         SendDigitsToLinks(rowD, 11, 4);
        integer Dcol1 = (integer)llGetSubString(rowD, 2, 2);
        integer Dcol2 = (integer)llGetSubString(rowD, 1, 1);
        integer Dcol3 = (integer)llGetSubString(rowD, 0, 0);
        llMessageLinked(11, Dcol0, "", "");
        llMessageLinked(12, Dcol1, "", "");
        llMessageLinked(13, Dcol2, "", "");
        llMessageLinked(14, Dcol3, "", "");
    } else if (!current_rowD) {
        llMessageLinked(11, 0, "", "");
        llMessageLinked(12, 0, "", "");
        llMessageLinked(13, 0, "", "");
        llMessageLinked(14, 0, "", "");
     }
     }
      
     else if (!current_rowD)
        SendDigitsToLinks("0000", 11, 4);
 
     integer current_rowE = llList2Integer(bTime, 4);
     integer current_rowE = llList2Integer(bTime, 4);
     integer old_rowE = llList2Integer(oTime, 4);
     if (current_rowE != llList2Integer(oTime, 4))
    if (current_rowE != old_rowE)
     {
     {
         string rowE = dec2bin(current_rowE);
         string rowE = dec2bin(current_rowE);
         integer Ecol0 = (integer)llGetSubString(rowE, 3, 3);
         SendDigitsToLinks(rowE, 15, 3);
        integer Ecol1 = (integer)llGetSubString(rowE, 2, 2);
        integer Ecol2 = (integer)llGetSubString(rowE, 1, 1);
        llMessageLinked(15, Ecol0, "", "");
        llMessageLinked(16, Ecol1, "", "");
        llMessageLinked(17, Ecol2, "", "");
    } else if (!current_rowE) {
        llMessageLinked(15, 0, "", "");
        llMessageLinked(16, 0, "", "");
        llMessageLinked(17, 0, "", "");
     }
     }
      
     else if (!current_rowE)
        SendDigitsToLinks("000", 15, 3);
 
     integer current_rowF = llList2Integer(bTime, 5);
     integer current_rowF = llList2Integer(bTime, 5);
     integer old_rowF = llList2Integer(oTime, 5);
     if (current_rowF != llList2Integer(oTime, 5))
    if (current_rowF != old_rowF)
     {
     {
         string rowF = dec2bin(current_rowF);
         string rowF = dec2bin(current_rowF);
         integer Fcol0 = (integer)llGetSubString(rowF, 3, 3);
         SendDigitsToLinks(rowF, 18, 4);
        integer Fcol1 = (integer)llGetSubString(rowF, 2, 2);
        integer Fcol2 = (integer)llGetSubString(rowF, 1, 1);
        integer Fcol3 = (integer)llGetSubString(rowF, 0, 0);
        llMessageLinked(18, Fcol0, "", "");
        llMessageLinked(19, Fcol1, "", "");
        llMessageLinked(20, Fcol2, "", "");
        llMessageLinked(21, Fcol3, "", "");
    } else if (!current_rowF) {
        llMessageLinked(18, 0, "", "");
        llMessageLinked(19, 0, "", "");
        llMessageLinked(20, 0, "", "");
        llMessageLinked(21, 0, "", "");
     }
     }
          
    else if (!current_rowF)
         SendDigitsToLinks("0000", 18, 4);
}
 
MessageLinked(integer inputLinkNumber, integer inputNumber)
{
    llMessageLinked(inputLinkNumber, inputNumber, "", "");
}
}


Line 157: Line 105:
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         if (!token && llDetectedKey(0) == llGetOwner())
         if (llDetectedKey(0) != llGetOwner() )
            return;
        if ( !(token = !token) )
            llOwnerSay("Off!");
        else
         {
         {
             oTime = [];
             oTime = bTime = [];
            bTime = [];
            llSetTimerEvent(1.0);
            token = 1;
             llOwnerSay("On!");
             llOwnerSay("On!");
         }
         }
          
         llSetTimerEvent(token);
        else if (token && llDetectedKey(0) == llGetOwner())
        {
            llSetTimerEvent(0);
            token = 0;
            llOwnerSay("Off!");
        }
     }
     }
   
 
     timer()
     timer()
     {
     {
Line 181: Line 124:
     }
     }
}
}
</lsl>
</source>
{{LSLC|Library|Binary Clock}}
{{LSLC|Library|Binary Clock}}

Latest revision as of 18:27, 24 January 2015

Binary Clock V1.2

// 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();
    }
}