User:Toady Nakamura/Simple Recording Tipjar: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Kireji Haiku (talk | contribs)
m rewrote second example script using variable names that actually mean something and improved readability and memory usage
Toady Nakamura (talk | contribs)
m →‎Fancier Recording Tipjar: cleaned up variable names to be less confusing to beginners. I use these scripts as class examples, please do not over complicate them.
Line 38: Line 38:


==Fancier Recording Tipjar==
==Fancier Recording Tipjar==
I found this one on the LSL-101/Logic page and added it here for reference so you can see the difference between a simple script and one which is a bit more complicated.  This one shows  
I found this one on the LSL-101/Logic [https://wiki.secondlife.com/wiki/LSL_101/Logic] page and added it here for reference so you can see the difference between a simple script and one which is a bit more complicated.  This one shows  
*Donations so far
*Donations so far
*Last donation
*Last donation
Line 54: Line 54:
string lastDonor;
string lastDonor;


vector colorWhite = <1.0, 1.0, 1.0>;
vector white = <1.0, 1.0, 1.0>;
vector colorRed = <1.0, 0.0, 0.0>;
vector red = <1.0, 0.0, 0.0>;
vector colorYellow = <1.0, 1.0, 0.0>;
vector yellow = <1.0, 1.0, 0.0>;


float floattextAlpha = 1.0;// [0.0, 1.0]
float alpha = 1.0;// [0.0, 1.0]


default
default
Line 80: Line 80:
         llSetPayPrice(20, [10, 20, 50, 100]);
         llSetPayPrice(20, [10, 20, 50, 100]);


         llSetText(ownerName + "\ndonations so far: 0 L$\n ", colorWhite, floattextAlpha);
         llSetText(ownerName + "\ndonations so far: 0 L$\n ", white, alpha);
     }
     }


Line 88: Line 88:
         string firstName = llGetSubString(name, 0, llSubStringIndex(name, " ") - 1);
         string firstName = llGetSubString(name, 0, llSubStringIndex(name, " ") - 1);


    //  PUBLIC_CHANNEL has the integer value 0
         llSay(0,"Thank you for the donation, " + firstName + "!");
         llSay(PUBLIC_CHANNEL,
            "Thank you for the donation, " + firstName + "!");


         totalDonations += amount;
         totalDonations += amount;
Line 96: Line 94:
         lastDonation = amount;
         lastDonation = amount;
         lastDonor = name;
         lastDonor = name;
         vector colorToUse = colorYellow;
         vector colorSet = yellow;


         if (topDonation < lastDonation)
         if (topDonation < lastDonation)
Line 102: Line 100:
             topDonation = lastDonation;
             topDonation = lastDonation;
             topDonor = lastDonor;
             topDonor = lastDonor;
             colorToUse = colorRed;
             colorSet = red;
         }
         }


         llSetText(ownerName
         llSetText(ownerName
                     +"\ndonations so far: " + (string)totalDonations + " L$"
                     + "\n donations so far: " + (string)totalDonations + " L$"
                     + "\nlast donation: " + (string)lastDonation + " L$ (" + lastDonor + ")"
                     + "\n last donation: "   + (string)lastDonation   + " L$ (" + lastDonor + ")"
                     + "\ntop donation: " + (string)topDonation + " L$ (" + topDonor + ")",
                     + "\n top donation: "     + (string)topDonation   + " L$ (" + topDonor + ")",
                        colorToUse, floattextAlpha);
                          colorSet, alpha);
     }
     }
}
}
</lsl>
</lsl>

Revision as of 12:14, 30 October 2012

  • Put this script in any object you own for an instant tipjar.
  • By Toady Nakamura

<lsl> integer totaldonated;

default {

   on_rez( integer sparam )
   {
       llResetScript(); // reset when rezzed out
   }
   state_entry()
   {
       llSetText("Donation Box\nL$0 Donated so far",<1.0,1.0,1.0>,0.85);
       // set text, "message", color vector (here white), and intensity (here 85%)
   }
   money(key id, integer amount)// When someone pays the system records their key & the amount
   {
       totaldonated = totaldonated + amount;
       // add the amount just given to the total from before
       // "amount" comes from the money event
       llSetText("Donation Box \n L$" + (string)totaldonated + " Donated so far",<1.0,1.0,1.0>,0.85);
       // set the text to show the gift
       llInstantMessage(id,"Thank you for the donation!, " + llKey2Name(id));
       // send a private thank you to giver.
       // "id" comes from the money event
       llInstantMessage(llGetOwner(), llKey2Name(id) + " just donated $L" + (string)amount);
       // privately message owner to say how much the donation was and the name of the giver.
   }

} </lsl>

Fancier Recording Tipjar

I found this one on the LSL-101/Logic [1] page and added it here for reference so you can see the difference between a simple script and one which is a bit more complicated. This one shows

  • Donations so far
  • Last donation
  • Largest donation

<lsl> string ownerName;

integer totalDonations;

integer topDonation; integer lastDonation;

string topDonor; string lastDonor;

vector white = <1.0, 1.0, 1.0>; vector red = <1.0, 0.0, 0.0>; vector yellow = <1.0, 1.0, 0.0>;

float alpha = 1.0;// [0.0, 1.0]

default {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   changed(integer change)
   {
       if (change & CHANGED_OWNER)
           llResetScript();
   }
   state_entry()
   {
       key ownerKey = llGetOwner();
       ownerName = llKey2Name(ownerKey);
       llSetPayPrice(20, [10, 20, 50, 100]);
       llSetText(ownerName + "\ndonations so far: 0 L$\n ", white, alpha);
   }
   money(key id, integer amount)
   {
       string name = llKey2Name(id);
       string firstName = llGetSubString(name, 0, llSubStringIndex(name, " ") - 1);
       llSay(0,"Thank you for the donation, " + firstName + "!");
       totalDonations += amount;
       lastDonation = amount;
       lastDonor = name;
       vector colorSet = yellow;
       if (topDonation < lastDonation)
       {
           topDonation = lastDonation;
           topDonor = lastDonor;
           colorSet = red;
       }
       llSetText(ownerName
                   + "\n donations so far: " + (string)totalDonations + " L$"
                   + "\n last donation: "    + (string)lastDonation   + " L$ (" + lastDonor + ")"
                   + "\n top donation: "     + (string)topDonation    + " L$ (" + topDonor + ")",
                         colorSet, alpha);
   }

} </lsl>