Thursday, February 7, 2008

The Gadget Alpha Code

Here we go. One of the big problems of second life is the problem of http length limits. Another big problem is the lack of external reference. This gadget will help fix both

[Updated to newest version]


// wiki reader .1 Lillie Yifu
// http://sexsecond.blogspot.com
// chat on channel 4 the name of an article to get the top of the entry text
// permission is granted to distribute this script free and open source with the header attached


key hid;
string name;
string str_replace(string src, string from, string to)
{//replaces all occurrences of 'from' with 'to' in 'src'.
integer len = (~-(llStringLength(from)));
if(~len)
{
string buffer = src;
integer b_pos = -1;
integer to_len = (~-(llStringLength(to)));
@loop;//instead of a while loop, saves 5 bytes (and run faster).
integer to_pos = ~llSubStringIndex(buffer, from);
if(to_pos)
{
buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
jump loop;
}
}
return src;
}
key image = "f07b2853-6aa2-7819-cbde-a1bf4187091d";
vector large = <0.01,0.3,.3>;
vector small = <0.01,0.1,0.1>;
integer islarge =TRUE;

string url = "http://secondlife.wikia.com/index.php?action=raw&title=";
//string url = "http://en.wikipedia.org/index.php?action=raw&title=";
integer chan = 4;
default
{
state_entry()
{
llSetTexture(image,ALL_SIDES);
llOwnerSay("Chat on channel "+(string) chan+" the name of an article to reference the Second Life Wiki.");
llListen(chan,"",llGetOwner(),"");
}

listen(integer c,string n,key id,string m)
{

name=url+str_replace(m," ","_");

llOwnerSay(name);
list meta = [HTTP_MIMETYPE,"text/plain;charset=utf-8"];
hid = llHTTPRequest(name, meta, "");
}
on_rez(integer p)
{
llResetScript();
}
touch_start(integer p)
{
if(islarge) {
llSetScale(small);
islarge = FALSE;
llSetAlpha(.3,ALL_SIDES);
} else {
llSetScale(large);
islarge = TRUE;
llSetAlpha(1.,ALL_SIDES);
}
}


http_response(key request_id, integer status, list metadata, string body)
{
key image;
if (request_id == hid)
{
llOwnerSay(body);
image = (key)llGetSubString(body,5,40);
llSetTexture(image,ALL_SIDES);


}
}

}




What it does: I put it in a HUD, but when rezzed it listens on channel 4. It then looks up in the Second Life Wiki the article. I need to add in redirect intercepts and fix some formatting things so it can read wikipedia.

Try it with Lillie Yifu.

This will work with any mediawiki installation that supports the action=raw input. Right now the lsl wiki does not. But we can fix that. Why aren't I selling this? Because it would be wrong, and it is too useful as open source. This means that if you can set up a mediawiki, and there are close to free options, you can store text. There are lots of features to add to this bit of code. But it works in the basic sense.

Now what we need is for people to start filling out the second life wiki...

2 comments:

  1. I don't understand the usefulness of a response like this:
    [7:49] Object: http://secondlife.wikia.com/index.php?action=raw&title=Prim
    [7:49] Object: The word '''prim''' is a shortened version of "primitive" and refers to the 3D [[polygon]]al shapes used by [[resident]]s to build [[object]]s in [[Second Life]]. Commonly used primitive shapes are [[cube]]s, [[sphere]]s, and [[cylinder]]s which can all be "[[link]]ed" together to form more complex objects. Other types of prims are [[prism]]s, [[tori]], [[ring]]s, and [[tubes]]. Prims can be [[Edit Window|edited]] in a multitude of ways ([[parameter]]s/[[property|properties]]): [[scale]], [[cut]], [[hollow]], [[twist]], [[dimple]], [[shear]], [[skew]], [[revolve]], [[radius delta]], set [[physical]], made [[flexible]] and/or a [[light]], and more.

    {| class="wikitable" style="text-align:center"
    |+ Prim types in Second Life
    ! Box
    ! Prism
    ! Sphere
    ! Cylinder
    |-
    | [[Image:prim_type_box.jpg]]
    | [[Image:prim_type_prism.jpg]]
    | [[Image:prim_type_sphere.jpg]]
    | [[Image:prim_type_cylinder.jpg]]
    |-
    ! Torus
    ! Tube
    ! Ring
    |-
    | [[Image:prim_type_torus.jpg]]
    | [[Image:prim_type_tube.jpg]]
    | [[Image:prim_type_ring.jpg]]
    |

    Can you explain a bit more how you use it?

    ReplyDelete
  2. To explain, it is very annoying to read with all those [[]].
    Those could be removed, of course. Then it might make sense. :P

    But how do tables look like, tables like often see in LSL function definitions.

    ReplyDelete