« Snow Crashed, Analytics Data | Main | SLTutorials Website »

Cylindrian's Tip/Info/Vending Sign (Part 4)

This is part four in a series of howto entries.

Quick aside: I heard from Crap Mariner recently regarding this project. He was nice enough to compliment the work and had one amusing suggestion. Crap suggests 'a counter for the number of broken strings. Or "X Days Without A Broken Guitar String"'. If you have seen a Cylindrian concert and chanted for her while she was tuning then you know what this is in reference to, don't you?

Tip Scripts Including Work Around

The script for the tip jar was created by Mera Pixel. I took some liberties, added some features to solve for a few edge cases, created our money() event work around, etc.

The New Tip Script

Since the money() event in the root prim was triggering at unpredictable times after I linked in my 3rd party vendor object I had to come up with a new approach. Our sign is going to have a single large background prim and I originally had that in mind as the root prim. Instead we can make the root prim invisible and make a child prim, the one with the tip script, the large background prim.

Push the root prim out of the way and expand the size of the latest child prim - Child2. Just be sure that the "Edit linked parts" checkbox is on so that you can manipulate position and size of individual prims in the object.

ModifiedTestObject.jpg

While still editing linked parts delete the Tip Jar script we created from "Root Prim" and from "Child Prim". This removes all money() event handling except for those built into our vendor prim. Add the following script into the new background prim by editing the "Child2" prim, creating a new script, renaming it to "Tip Script (Open Source)" and replacing the default script with the following:


// Tip Controller
// created by Mera Pixel
// modified by Dolmere Talamasca

///////////// VARIABLES YOU MIGHT WANT TO CUSTOMIZE ////////////

// Text to display as hover text on top of your object
string objText = ""; // Perhaps "My Tip Jar" or "Tip Me", etc

// Should this tip jar thank the user in general chat?
integer speak_tips = FALSE;

// Color for your setText
integer colorR = 164;
integer colorG = 40;
integer colorB = 40;

///////////// NO NEED TO EDIT BEYOND HERE ////////////

// the owner of the object with this script... likely you
string ownername;

// Store the amount being tipped
integer amount;
// Keep track of the total amount tipped
integer total;
// the tipper
key tid;

// List of who tipped
list tippers_list = [];
// List of how much they tipped
list tip_amt = [];

// color values in SL form (0.0 - 1.0)
float textR;
float textG;
float textB;

key tquery; //track the data server query as not to repond to other events.

default
{
// Initialize our script here
state_entry()
{
// Define the set text color in SL color form.
textR = colorR/255.0;
textG = colorG/255.0;
textB = colorB/255.0;
// Get the owner name
ownername = llKey2Name(llGetOwner());
// blank out our lists and totals
tippers_list = [];
tip_amt = [];
total = 0;
// Display our set text
llSetText(objText,,1);
// Announce our readiness to our owner
llOwnerSay ("Tip object for " + ownername + " is now ready..." );
}

on_rez(integer unused)
{
llResetScript();
}

money( key id, integer payment )
{
// Get how much was paid
amount = payment;
// Get who paid it
tid = id;
// Get some information on our tipper
tquery = llRequestAgentData( id, DATA_NAME );
}

link_message(integer sender_num, integer payment, string in_trigger, key id)
{
// If we receive a TIP_RECEIVED link message then another child prim in our object has received a direct payment and this tip script should register it.
if (in_trigger == "TIP_RECEIVED") {
// Get how much was paid
amount = payment;
// Get who paid it
tid = id;
// Get some information on our tipper
tquery = llRequestAgentData( id, DATA_NAME );
}
}

dataserver(key query, string name)
{
if (tquery == query) {
integer i=0;
integer tipperFound = 0;
integer tipperIndex = 0;
integer tipperTotal = 0;
list tipperTotalList = [];
// Search for our tipper in or tipper list
tipperIndex = llListFindList(tippers_list, [name]);
if (tipperIndex >= 0) {
tipperTotal = llList2Integer(tip_amt, tipperIndex);
tipperFound = 1;
} else {
tipperFound = 0;
}
// Add to the tipper total amount
tipperTotal += amount;
// Make a list entry for this tipper total amount
tipperTotalList = [tipperTotal];
// If this is a duplicate tipper, say something nifty
if (tipperFound > 0) {
if (speak_tips == TRUE) {
llSay( 0, name + " just tipped again! Thank you very much!");
}
llInstantMessage(tid, "Thank you for tipping again, " + llGetSubString(name, 0, llSubStringIndex(name, " ")) + ". You've tipped " + (string)tipperTotal + "L total!");
tip_amt = llListReplaceList(tip_amt, tipperTotalList, tipperIndex, tipperIndex);
} else {
// First time tipper, express our gratitude
if (speak_tips == TRUE) {
llSay( 0, "Thank you, " +name + " for tipping " + ownername + " " + (string)amount + "Lindens");
}
llInstantMessage( tid, "Thank you for the tip " + llGetSubString( name, 0, llSubStringIndex( name, " ")));
tippers_list += [name];
tip_amt += [tipperTotal];
}
total = total + amount;

// Reset the object setText with some updated info
llSetText(objText + "\nLast tip was from: " + name , ,1 );

// Update the owner with some tip details
llOwnerSay("**" + name + " just donated " + (string)amount + " Their Total: " + (string)tipperTotal + " Tips so far: " + (string)total);
}
}
}


Let's discuss the variables that you might want to customize. Notice this area towards the top of the new tip script:

Variables You Might Want To Edit

///////////// VARIABLES YOU MIGHT WANT TO CUSTOMIZE ////////////

// Text to display as hover text on top of your object
string objText = ""; // Perhaps "My Tip Jar" or "Tip Me", etc

// Should this tip jar thank the user in general chat?
integer speak_tips = FALSE;

// Color for your setText
integer colorR = 164;
integer colorG = 40;
integer colorB = 40;

The variable objText is currently set to an empty string. You can change it to customize the text message that will display as hovertext over your object (hovering atop the prim where this tip jar script resides).

The variable speak_tips can be set to TRUE or FALSE and is used to tell the script whether or not to thank the tipper in general chat. If FALSE (as it is now) the object will just send a thank you directly in IM to the tipper as well as alerting the owner to the tip. If TRUE it will do both of those steps but also write a thank you message to channel 0, general group chat, which anyone in chat distance could read.

The variables colorR, colorG, colorB represent the 0-255 color value of red, green and blue for your hover text. In photoshop select a color and in the color picker window find the R,G,B color values (just over the hex#) and plug them in here.

The Work Around - Listening For Linked Messages

This script contains two places to handle a donation. The obvious one is the money() event but the second one is an event that handles linked messages. Since our root prim can't handle money() events that means every child prim you want to be able to receive one of those events for your object either has to have its own tip jar script or has to find a way to pass the details of the payment along. If we had copies of a tip jar script all over our object we'd have replication for no real reason and independent totals. Instead we'll have our child prims just send a message with the relevant information along to our single tip script so that it can handle the event normally.

The Work Around - Generating Linked Messages

That means we need a script in each child prim that we want to pass a money() event along which will generate a linked message. Edit the "Child Prim", create a new script and name it "Tip jar component". Replace its default script with the following script:


// Tip jar component
// By Dolmere Talamsca
//
// Send a linked message when we receive a tip/money event so that another script
// in this object can react to the payment.
//
// In this project our tip jar script cannot be in the root prim (because we have other attached child prims that need to reacts on their own to Money() events)
// So we place this script into each child prim that we want to receive payments but pass the data along to the primary tip jar script (located in some other child prim of this object)

default {
money( key id, integer payment ) {
llMessageLinked(LINK_SET, payment, "TIP_RECEIVED", id);
}
}

Verification

Now test your object. What happens if you pay the vendor prim - does the tip jar script attempt to recognize the event as a tip? What happens if you try to pay the root prim? What happens if you pay the "Child Prim"? What about paying the "Child2" prim which actually contains the tip script?

You should NOT place a copy of the "Tip jar component" script into the root prim! Why? It would re-introduce our original problem of passing the vendor money() events along to our tip script. To test this through you might add a copy of the script to the root prim and test paying each prim in the object to see how it affects behavior. When done delete the script from the root prim.

In the next section I'll introduce a script for managing a dialog system.

TrackBack

Listed below are links to weblogs that reference Cylindrian's Tip/Info/Vending Sign (Part 4):

» Cylindrian's Tip/Info/Vending Sign (Part 5) from Dolmere Talamasca - Second Life "resident"
This is part five in a series of howto entries. Dialog Menus To review I'll repost Cylindrian's original list of items she wanted condensed into a single sign: Donations/Tips --... [Read More]

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Recent Comments

Melynn said: The purple/pink guitar is in small pieces now, so it's a toad-ily mute point anyway. :) That's even more amusing.…

Crap Mariner said: You know, it would be amusing to have the equivalent of a Turing Test to see if people could figure out if a stream of chat is actually from me or if it's from …

Dolmere Talamasca said: One might note that the JIRA bug now has 650 votes for it. Keep 'em coming people, it's easy to login and add your vote if you think something like this is need…

Dolmere Talamasca said: Interesting way of looking at it, Vint. I would think more PA than PS but unpaid labor is still unpaid labor.…

Dolmere Talamasca said: Instead of the typing animation use "UISndTyping" and clear the field to accomplish the closest thing to what I'm looking for (As noted by Jacek at Crap Mariner said: *shrug* Got time to hit the tower on Monday with Cyl and SUPRISE SPECIAL GUEST? Not sure which song... um... Rainbow Connection would be cool basstasstically…