About

The SL Developer’s Corner is my place in the virtual world “Second Life”, where i experiment and tinker with the features of this platform. I try to publish my experiences and often also include the source code of the scripts on this site. Other posting related to Second life can be also found on Happy Coding 2nd-life section.

Friday, 30 March 2007

The Second Life "Twitter Wristlet"

I have created a little accessory for the Twitter-service in SL. It allows you to move around in the world with the "stylish" possibility to send some updates to twitter. I call it the "Twitter Wristlet", because its a wristlet. ;)

The only differences between the wristlet and my other fixed Twitter-service are the following:

  1. The wristlet doesn't create objects on which the tweets (status-updates) are displayed. I just prints them to screen using llOwnerSay.
  2. Because it can be very disturbing to have half of the screen full of Twitter-updates, you can stop/start the timer which receives the tweets.
Note: When you are on land where running scripts is not allowed, it won't work. Does anyone know how to bypass this? Or is it impossible?

The LSL-code for the wristlet looks like that. I use the Chatchannel 998 for communicating with the wristlet.

key requestId;
list resultList;
string rawList;
float refreshTime = 30.0;

default
{
state_entry()
{
integer i;
rawList = "";
llSetTimerEvent(refreshTime);
llListen(998, "", llGetOwner(), "" );
}

listen(integer channel, string name, key id, string message) {
if(message == "#stop#") {
// stops the automatic refresh of the tweets
llSetTimerEvent(0.0);
llOwnerSay("The automatic refresh has been stopped. Reactivate using #start#");
} else if(message == "#start#") {
llSetTimerEvent(refreshTime);
llOwnerSay("Refresh will taking place every " + (string)refreshTime + " seconds. Stop using #stop#");
} else {
llOwnerSay("trying to send your status message: " + message);
llHTTPRequest("###YOUR RUBY URL###/twitter/post_message",[HTTP_METHOD,"POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],"msg="+message);
llOwnerSay("ok, status has been sent.");
}
}

timer() {
llOwnerSay("loading tweets...");
requestId = llHTTPRequest("###YOUR RUBY URL###/twitter/get_messages?type=public",[HTTP_METHOD,"GET"],"");
}

http_response(key request_id, integer status, list metadata, string body) {
integer i;

if (request_id == requestId) {
rawList = body;

// create the boxes from the list information
resultList = llParseString2List(body,["\n"],[]);
integer listlength = llGetListLength(resultList);
float boxPosition = 1;

for(i=0;i<listlength;i+=1) {

string statusLineWithName = llList2String(resultList, i);
list statusParts = llParseString2List(statusLineWithName, ["|"], []);
string text = llList2String(statusParts, 0);
string name = llList2String(statusParts, 1);
llOwnerSay(name + ": " + text);
}

} else {
// llSay(0,(string)status+" error");
}
}
}

3 comments:

57 Miles said...

Hey this sounds great! But how do we get it, or created it?

daniel said...

The linden script code is included in this post. As a backend for connecting to twitter i use the Ruby on Rails stuff i wrote about in one of my last postings.

The only way to use it now, is to setup your own server & co.
But i will think about a way, that also other users can use my server. :) So stay tuned.

57 Miles said...

Ok thanks, do let me know!