Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Writing Commerce Scripts in Second Life : Page 3

Millions of dollars change hands in Second Life. Find out how to create scripts to sell items in your own Second Life store.


advertisement
Loading Items
When the default state fires, and there are no items loaded, the script sets the loading state, which begins by submitting a query to read the notecard:

state loading { state_entry() { llSay(0,"Loading product data..."); notecardIndex = 0; notecardQuery = llGetNotecardLine( notecardName,notecardIndex++); }

The script reads lines one at a time from the notecard. After reading each line, the script calls the dataserver event handler:

dataserver(key query_id, string data) { if ( notecardQuery == query_id) {

The script stops reading when it reaches the end of the notecard, and returns to the default state:



if (data == EOF) { llSay(0,"Products loaded..."); state default;

Until it reaches the end of the notecard data, it adds the data read to the notecardList variable:

} else { notecardList += [data]; notecardQuery = llGetNotecardLine( notecardName,notecardIndex++); } } } }

There are three other scripts in the vendor object that handle navigation and display of the textual information about the item.

Vendor Navigation Scripts
The vendor object has two buttons that allow navigation. Clicking the Forward and Back buttons switches the display of the current object for sale. Here's the Forward button's script:

default { touch_start(integer total_number) { llMessageLinked(LINK_ALL_OTHERS , 0, "forward", NULL_KEY); } }

Touching the Forward button simply sends a "forward" message that will be picked up by the main vendor script. The vendor object can also go backward. The Back button's script is identical, except that it sends a "back" message:

default { touch_start(integer total_number) { llMessageLinked(LINK_ALL_OTHERS , 0, "back", NULL_KEY); } }

The Buy button just displays instructions on buying—to buy an item you just pay the object, which purchases the item. However, the Buy button is useful because it is right under the texture, so adding text to the Buy button puts the text display right under the picture of the item. Here's the Buy button's script:

default { link_message(integer sender_num, integer num, string str, key id) { string prefix = llGetSubString(str,0,0); if( prefix==":" ) { string rest = llGetSubString(str,1,-1); llSetText(rest,<0,0,0>,1); } } }

The buy button simply waits for messages, and then displays them.

You've seen the fundamentals required to automate commerce in Second Life. Although the idea of selling virtual items in a virtual world may seem like play, real people earn their livings selling objects in Second Life. Vendor kiosks, such as the one you've seen here, are at the center of many Second Life stores because they let you sell items without having to display a physical copy of every item, thus reducing the amount of space required.

You can get a copy of the vending device (the kiosk) discussed in this chapter directly from Second Life by visiting the Second Live URL (SLURL) http://slurl.com/secondlife/Encogia/211/181/63 (you must be a member of Second Life to reach this SLURL). There you'll find the complete vendor script with full modify permissions. You can also download the scripts for this article, and build your own kiosk.



Jeff Heaton is an author, college instructor, and consultant. Jeff is the author of four books and over two dozen journal and magazine articles. Jeff maintains a personal website where he publishes information about artificial intelligence, spider/bot programming, and other topics.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap