Gromlok Darkwatch
Registered User
Join date: 27 Oct 2009
Posts: 1
|
02-08-2010 22:56
Hello: I'm currently development a mini tool in LSL to get information from SL. The idea is to get the relevant information from an Avatar and use it to see some patterns, if any. I'm new in LSL.
My question is: exist the object oriented paradigm in LSL? On the wiki there is an example, but is not totally developed and I did not find more information.
I want to create an AVATAR object -object in the context of programing, not in SecondLife-, so, for every avatar inside a specific island, get the relevant information, ex: name, region, agent info, agent data, etc.
By now, I created a script that collect some information and send it to a PostgresSQL database, but is all mixed depending of the avatar and I don't have control to easy differentiate the data.
Could yo recommend me something?
Here is my code: /***********************************************************/ key http_request_id; string url = "http://yourpage/update.php"; list http_prop = [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"]; string http_data; default { state_entry() { string sl_region = llGetRegionName(); key sl_owner = llGetOwner(); string sl_name = llKey2Name(sl_owner); integer sl_agent = llGetAgentInfo(sl_owner); string agent_always_run = "0"; string agent_attachments = "0"; //Not Secure. Go to SL documentation WIKI. //http://wiki.secondlife.com/wiki/AGENT_AUTOPILOT //string agent_autopilot = "0" string agent_away = "0"; string agent_busy = "0"; string agent_crouching = "0"; string agent_flying = "0"; string agent_in_air = "0"; string agent_mouse_look = "0"; string agent_on_object = "0"; string agent_scripted = "0"; string agent_sitting = "0"; string agent_typing = "0"; string agent_walking = "0"; if (sl_agent & AGENT_ALWAYS_RUN) agent_always_run = "1"; if (sl_agent & AGENT_ATTACHMENTS) agent_attachments = "1";
if (sl_agent & AGENT_AWAY) agent_away = "1";
if (sl_agent & AGENT_BUSY) agent_busy = "1";
if (sl_agent & AGENT_CROUCHING) agent_crouching = "1";
if (sl_agent & AGENT_FLYING) agent_flying = "1";
if (sl_agent & AGENT_IN_AIR) agent_in_air = "1";
if (sl_agent & AGENT_MOUSELOOK) agent_mouse_look = "1";
if (sl_agent & AGENT_ON_OBJECT) agent_on_object = "1";
if (sl_agent & AGENT_SCRIPTED) agent_scripted = "1";
if (sl_agent & AGENT_SITTING) agent_sitting = "1";
if (sl_agent & AGENT_TYPING) agent_typing = "1";
if (sl_agent & AGENT_WALKING) agent_walking = "1"; http_data = "sl_region= " + sl_region + " sl_owner= " + (string)sl_name + "flying="+(string)agent_flying + "walk="+(string)agent_walking; http_request_id = llHTTPRequest(url, http_prop, http_data); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == http_request_id) { llSetText(body, <0,0,1>, 1); } } } /***********************************************************/
As you can see, I send the information in a ugly string -"http_data"-, all together. I would like to send every piece of information individually and just ONE time per avatar in the relevant case, like, for example the region: I don't have to send the region of an "X" avatar every certain amount of time, once is enough. In the case of "walking", "flying", etc., every certain amount of time this information must be send it.
Any help, please?
Thank you very much.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-09-2010 08:23
you can implement OOP in LSL, but then you're stuck storing it there... you can fake it for your outside database as you have, but then all your update methods will be implemented on the LSL side as you've noticed
note I said fake it, because essentially your avatar_object is now inclusive of the lsl program methods to get/update, as well as you webside database, and the transport protocol... which is about as tight a binding as you can get in this case.
lsl is not really designed for OOP, but the method I've used is to store all the properties as separate lists, each increment of which is a new object. in the case of an av, I make the av_key be essentially the name of the object. methods are individual functions that take the av key as a parameter, with any parameters for the method as a list, so that I can define some as optional (dear god I wish we had actual optional parameters). get/set operations I generalize as a function that takes 3 parameters, the av_key, the property, and a get/set flag (to make reusability in LSL nicer).
another paradigm would be to use link messages, and treat one script as an object, or even a collection, and let all methods/gets/sets be channeled through link messages... this is a very true version of a black box object.
as for how to improve you message handling between the lsl data collector and the webside storage... since you already know that llGetAgentInfo returns a bit field, why not just store that raw as is, instead of making separate containers for it? even assuming you manipulate that information on the webside, bit masking operations are going to be faster there than in SL.
if you feel you absolutely must do it on the sl side, than eliminate some of your work and simply mask and bitshift that data into place...
in you're example, I'd always send the key of the av, as it's unique marker to tell you what record to update, and there's no need to store it locally, simply use llGetOwner with every update call. region doesn't need to be stored because you can get it from the changed event when it' changes, if the item is worn, otherwise store locally; you can store the bitfield from llGetAgentInfo locally, and only send if it changes.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
separate message to avoid fourm funkiness with sql keywords
02-09-2010 08:24
ex: assuming an object that's worn, and polls status for walking etc flags string gStrURL = "http://yourpage/update.php"; list gLstPRP = [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"];
integer gBitInf; string gStrSnt; key gKeyRqs;
default{ on_rez( integer vIntNul ){ gKeyRqs = llHTTPRequest( gStrURL, gLstPRP, gStrSnt = "Key=" + (string)llGetOwner() + "Region=" + llGetRegion() + "Flags=" + ((string)(gBitInf = llGetAgentInfo()) ); llSetTimerEvent( 600.0 ); //-- 10 minute updates }
timer(){ integer vBitInf = llGetAgentInfo(); if (gBitInf & vBitInf){ gKeyRqs = llHTTPRequest( gStrURL, gLstPRP, gStrSnt = "Key=" + (string)llGetOwner() +"Flags=" + (string)(gBitInf = vBitInf) ); } }
changed( integer vBitInf ){ if (CHANGED_REGION & vBitInf){ gKeyRqs = llHTTPRequest( gStrURL, gLstPRP, gStrSnt = "Key=" + (string)llGetOwner() +"Region=" + llGetRegion() ); } }
http_response( key vKeyRqs, integer vIntSts, list vLstMta, string vStrBdy ){ if (gKeyRqs == vKeyRqs){ if (200 == vIntSts){ llSetText( vStrBdy, < 0.0, 0.0, 1.0 >, 1); }else{ gKeyRqs = llHTTPRequest( gStrURL, gLstPRP, gStrSnt ); } } } }
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Pavcules Superior
Registered User
Join date: 30 Oct 2006
Posts: 69
|
02-09-2010 10:48
Here is an implementation of a form of OO in LSL:  It is a bit of an overkill for your needs. But as Void said about storing items in Lists, the OO code is doing exactly the same thing. Easier to keep the code simple.
|