Thursday 9 June 2011

Second Life - My Last blog

Introduction

My last blog was about sending emails and receiving Notecards. In this week's blog I will try to describe how prims can be configured to receive and forward Notecards and receive emails.

Creating a post box system

A Post Box is an object that enables users to drop/post Notecards. In addition, the Post Box system must enable the Owner to collect, read and manage posted Notecards. To achieve this requirements, I created an object that enables Second Life residents to drag and drop Notecards to it and display the collected Notecards when touched by the owner. The following image shows the object:
The first thing that need to be done is to allow users to drag and drop Notecards into my Post Box. To allow drag and drop, I added the following syntax in the state_entry() event:
llAllowInventoryDrop(TRUE);
When this is enabled, dropped objects are added to the Post Box inventory.
To add some animation to my Post Box, I added the following script that is triggered when an object is dropped on the Post Box.
This simple animation will make the Post Box jump three times in the same location when an Notecard is dropped.
Line 12 checks two actions; If an object was dropped on the prim, or if the inventory list has changed. When one of these conditions is met, the script in lines 14 to 27 is executed.
In line 15, the Post Box location is stored in a vector using llGetPos(). The movement is stored in line 16 in a variable (move). Line 17 stores the loop pointer.
Using a for loop, lines 22 and 23 will move the object vertically 3 times. When the animation is complete, using llOwnerSay(string message), a notification is sent to the owner.
To test my script, I dropped two Notecards in my Post Box and checked my Post Box Contents. The Notecards where there...
The next step is to send the received Notecards to their owner. To achieve this, I added the folowing script in the touch_start() event; this event is triggered whenever an avatar touches my Post Box.
In line 24, the Owner UUID is stored in a key variable (OwnerKey). In line 38 the llDetectedKey(0) is used to get the UUID key of the avatar touching the prim; this is compared with the Owner UUID stored in OwnerKey.
If the Owner is touching the prim, using a for loop and llGiveInventory(key avatar ID, string Object name), all Notecards are forwarded to the owner. Within the loop, the following functions are used: 
  • llGetInventoryNumber(INVENTORY_NOTECARD) – This function is used to get the total number of Notecards in the inventory.
  • llGetInventoryName(INVENTORY_NOTECARD, integer index) – This function is used to get the name of a specific Notecards, at index.
When I touch the Post Box, the Second Live viewer will launch the following dialog for each Notecard:

Receiving emails

In my last blog, I described how to create an object that can send emails using the llEmail(string email address, string subject, string message). The next step is to enable a prim to receive emails.
First I created a simple prim and using llEmail() function, I sent an email to my inbox to determine the prim email address (<primid>@lsl.secondlife.com).
In the state_entry() event I added the following:
llSetTimerEvent(5,0);
This function will trigger the timer event every 5 seconds. In the timer event, I added the following code:
timer(){
llGetNextEmail(“”,””);
}
The llGetNextEmail(string address, string subject) function, will retrieve the first queued email message from address mail box with subject as the email subject. In this case, since the parameters are omitted, the function will return all emails.
The email() event is triggered when a new email is received. To display the message contents I added the following in the email() event:
Within the email() event, one can access the following parameters:
  • time – the email message time
  • address – the email message sender email
  • subject – the email subject
  • message – the email body
  • num_left – number of emails left in the mail box
In lines 17 to 19, using the llSay() function, the message, subject and address are being displayed. The following is an example:

Conclusion

Using emails and LSL, one can further enhance a prim to receive instructions via email. This means that a prim can be configured to receive instructions by emails, parse the contents and action accordingly. Sounds cool...
One can also enhance the Post Box system to convert Notecards to emails and forward them to the object owner.
Many technologies exist within second life, and hopefully I will try to experience them in the near future. For now, this is my last blog on Second Life cause I need to move on with other topics and technologies.
Good luck with Second Life....

No comments:

Post a Comment