Title: Emailing between objects
1Emailing between objects
- By Basil Wijaya
- New Business Horizons CTO
- 2008 May 19
2Email the color of the particles
3OBJECTIVES OF THE PRESENTATION WHAT
HOW
- Use email from object to object
- Verify how an email to an object permits to
control an action in that object
- Already done and full rights emailing and
receiving objects will be given to all
participants. - We will study together the major code lines
within the scripts included in examples.
4Use email from object to object
- The example gives 2 objects
- 1) Email sender (pink cube in the example)
- 2) Email receiver with particle system (white
cube) - Action
- 1) sends messages to 2)
- Once touched by owner, 2) starts reading the
messages it received and activates the particle
system related to the email message.
5Action the email sender sends messages to the
email receiver
- In order to send a message to the email receiver,
the email sender needs a unique identifier for
the email receiver. As with any email, this is
done using the email address. - An SL objects email address is done in the
following format - identifyer of object _at_lsl.secondlife.com
- The identifyer of object is what we call
- the key or the uuid
6How to get the object key and insert it in the
sender object script.
- In the receiver object, I have put a command to
tell you the name and the key of the object it is
in. - When rezzing the receiver object, you will get
the key in your chat. - Look at your chat. All SL keys (uuid) have the
same length 36 and are composed of letters,
numbers and -. Example - 477ac484-d79e-41d0-a7c5-758f6b29e065
- cont
7How to get the object key and insert it in the
sender object script
- Copy that key from your chat.
- Click on the sender object (pink) and choose Edit
in the pie menu. - Go to Content tab.
- Open the script by double-clicking on it.
- Locate the line
- key receiver_key "19e1403f-bb95-4f9f-9ff3-576e07
2d095a" - Replace the uuid on this line with the one you
copied from your chat. Click the save button. - Dont close the script. We will study it.
8- key receiver_key "477ac484-d79e-41d0-a7c5-758f6b
29e065" - string email_address
- default
-
- on_rez(integer i) llResetScript()
-
- state_entry()
-
- llSetText("Ready!\nTouch me to
execute\nthe email commands I contain.",lt0.0,1.0,0
.4gt,1.0) - email_address (string)receiver_key
"_at_lsl.secondlife.com" -
- touch_start(integer total_number)
-
- while(total_number--)
-
- if(llDetectedKey(total_number)
llGetOwner())
9Making the email address
- state_entry()
-
- //This line sets the text that appears over the
box - llSetText("Ready!\nTouch me to
execute\nthe email commands I contain.",lt0.0,1.0,0
.4gt,1.0) - //This line constructs the email address of the
receiver. - email_address (string)receiver_key
"_at_lsl.secondlife.com" -
- You see how the email address is constructed,
using the receiver_key variable that contains
the key that you received from the receiver and
copied. - (If you did not yet get the key of the receiver
object (white one), take it back in inventory and
rerez it. Check your chat to find the key and
copy it. Bring it in sender object script.)
10Sending the email messages
touch_start(integer total_number)
while(total_number--) //Do something
only when the owner touches the box
if(llDetectedKey(total_number) llGetOwner())
//Show a text saying what happens and
then send the 3 emails
llSetText("Emailing\nAllow 20 seconds for an
email \n 60 seconds for the 3 emails.",lt0.0,1.0,0.
4gt,1.0) llEmail(email_address,"A
message from " llKey2Name(llGetKey()),
"blue_color") llEmail(email_address,
"A message from " llKey2Name(llGetKey()),
"red_color") llEmail(email_address,"
A message from " llKey2Name(llGetKey()),
"stop_system") llSetText("After
emailing",lt0.0,1.0,0.4gt,1.0)
llSetTimerEvent(15.0) //Just to have the time
to see the After emailing text.
11Structure of an email
- Sending an email
- llEmail(string address, string subject, string
message) - An llEmail command needs an address to send to,
a subject and a message. - Receiving an email
- When received, an email event contains more
- email(string time, string address, string subj,
string message, integer num_left) - More in the message itself it contains the
region and location of the sending object. Check
next page example.
12Message received by receiver
- In the receiver script, I made the receiver say
the content of the message to the chat to show
you all its content, you will get some chat that
will ressemble the following lines - Email receiver with particle system I received
the following message - Object-Name Email sender
- Region Blue Horizon (204544, 314624)
- Local-Position (25, 28, 20)
- blue_color
13Lets look at the receiver box (white one) Email
receiver with particle system
- Right-click the receiver.
- In the pie menu, choose Edit.
- Go to the Content tab,
- Open the script, double-clicking it.
- Dont be afraid. At the beginning, there are some
particles systems script. We dont study that
now. - Go down till you see default.
14First make an empty particle system
- At the beginning of default, in the state_entry,
you will find - llParticleSystem()
- Whenever used, this command will stop the
particle system in the object.
15On touch by the owner, we retrieve a first email
with llGetNextEmail. If an email is there, the
email event will be raised (cont)
- touch_start(integer total_number)
-
- while(total_number--)
- //Only if owner
- if(llDetectedKey(total_number)
llGetOwner()) -
- //Say what happens
- llSetText("Retrieving my
emails\nIf no emails received\n nothing will
happen.",lt0.0,1.0,0.4gt,1.0) - //Get an email
- llGetNextEmail("", "") //IF
NO EMAIL, NOTHING HAPPENS -
-
-
16Syntax of llGetNextEmail
- A.86. llGetNextEmail
- llGetNextEmail(string address, string subject)
- Get the next waiting email with appropriate
address and/or subject. If the parameters are
blank, they are not used for filtering. - This means that if we specify an address, it
would be the incoming address of the sender. All
other messages coming from an other address to
that receiver would be ignored. For now we dont
need that level of security.
17Email event where we say what to do with the
received message content.
- email(string time, string address, string subj,
string message, integer num_left) -
- //Take a look at the received message.
You will see that it contains many parts. - llOwnerSay("I received the following
message \n" message "\n\nI have "
(string)num_left " messages left to
read...\n") - integer red_command llSubStringIndex(mes
sage,"red_color") - integer blue_command llSubStringIndex(me
ssage,"blue_color") - integer stop_command llSubStringIndex(me
ssage,"stop_system") -
- if (red_command ! -1)llSetColor(lt1.0,0.0
,0.0gt,1) particles_red() - else if (blue_command !
-1)llSetColor(lt0.0,0.0,1.0gt,1)
particles_blue() - else if (stop_command ! -1)
llSetColor(lt1.0,1.0,1.0gt,1) llParticleSystem()
-
- if (num_left gt 0)
-
- finished FALSE
- //Delay getting the next eamil to let
time to the particle system. - llSetTimerEvent(the_life)
-
18Checking the content of the message with
llSubStringIndex
- Fortunately here, I know what messages the sender
will send so I check in the received message if
I find what I need - llSubStringIndex will give us the index of the
searched text in the message. If that index is
not -1, it means that the text is contained in
the message - integer red_command llSubStringIndex(messag
e,"red_color") - if (red_command ! -1)
-
- llSetColor(lt1.0,0.0,0.0gt,1) //changes face 1
to color red. - particles_red() //calls a particle system
where I put red particles -
19The other commands I call while in the email event
- For each message retrieved, I check if there is a
red_color, blue_color or stop_system text
in the message. - If so, I send a choose the appropriate action
- red_color gt call particle_red function
- blue_color gt call particle_blue function
- stop_system gt stop the particle system.
20An important parameter num_left
- B.10. email
- email(string time, string address, string
subject, string body, integer remaining) - This event is triggered when an email sent to
this script arrives. The remaining tells how
many more emails are known as still pending. - What is important is the order of the parameters.
In my script, the parameter is named num_left, it
could be named remaining or an other name. - So we can check if some email is pending. If so,
we could want to retreive it, using
llGetNextEmail again.
21Timing is very important
- In the beginning of the receiver script, I setted
a variable named the_life. It is used to set the
length in seconds of the particle systems. - When the receiver receives a message, I evaluate
it and then call the appropriate particle
function. If the particle system is to last, say
15 seconds, I must time the retrieving of the
next email so that the first particle system will
have the time to execute completely. So I
introduced a timer that will use the same
variable life. This way, I will retrieve the
next email when the preceding particle system is
finished. - I will use this timer only to be sure that all
the particles will have the time to show.
22The timer event
- The timer event has been called by
llSetTimerEvent(the_life) - It contains the command that says to retrieve an
email - llGetNextEmail("", "")
- We will then go back in the email event. And so
on as long as there are messages to retrieve. If
no more messages, we empty the particle system.
Also there, we must time so that the particle
system will last the good amount of seconds
before stopping all.
23We can email to the particle system from an
outside email
- The email address of the object is real and not
only valid from inside SL. - Try sending a message to your particle box from
an external email hotmail, gmail, etc. - use the same address as in the script.
- in your email, write the message red_color .
Come back in SL, wait a bit, click your particle
box and watch the red particles.
24Last thing the particle system
- This was not a class on particle system but as
you have seen by now, the particles target to
Basil Wijaya. - To change that put your own uuid in the
particle script in the receiver, on the first
line - Replace Basils uuid with yours.
- key the_target ""
25This is all for now. As you can see, there are a
lot of things we can do with emails.