Kermitt Quirk
Registered User
Join date: 4 Sep 2004
Posts: 267
|
11-13-2005 18:36
From: Obsidian Stormwind I've noticed that many machines in Second Life use a separate script for each prim that acts as a button in an object, usually using a MessageLinked() function to send a message to the script in the root prim. However, seeing how this adds to the total script count in a SIM, I thought I'd post a way to reduce the need for these types of scripts. Obsidian Stormwind
This is definately a sensible solution, but people should be aware that there's a bit of a downside to not having a script with a touch_start event in each child prim. If there is a touch_start within a script in the child prim, and you right-click the child prim you'll get a Touch option in the pie menu. However, if there is no script in the child with a touch_start then right clicking that prim will not give you a Touch option. In most cases this isn't a problem, but it can be a real pain when you're testing something and you're in edit mode all the time. You have to switch edit mode off to actually trigger a touch in one of the children if all your touches are handled in the root. I have to admit that I wasn't really aware of this when I first wrote Tringo and in fact all the buttons on the cards do have separate scripts. As much as it's gonna suck trying to test without the touch_starts in the child prims I will almost definately be handling all the touches in the root for the next version. Most likely by comparing just the link number instead of the prim names though, since it seems a little uneccesary to be doing string comparisions when you should be able to guarantee the link order. Unfortunately, as the squares on the card become more complex I'll probably still end up having to have a script in each one anyway. 
|
Kermitt Quirk
Registered User
Join date: 4 Sep 2004
Posts: 267
|
11-13-2005 18:46
From: Argent Stonecutter Messages to single prims will still be sent direct to the prim, and responses use the num as a command... Comments on the performance and impact of this approach? I've used this technique of num for command and string for params quite often, but usually I'd build the string with pipes in between. I'd be interested if anyone knows which would be faster out of these two... string params = llList2CSV(param1, param2, param3);
...or...
string params = param1 + "|" + param2 + "|" + param3; Of course the parameters would often contain commas (especially if there's vectors in there), so I dunno if llList2CSV would really work in a lot of situations anyway.
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
11-13-2005 19:04
From: Kermitt Quirk Of course the parameters would often contain commas (especially if there's vectors in there), so I dunno if llList2CSV would really work in a lot of situations anyway. llList2CSV followed by llCSV2List absolutely does work with vectors. It doesn't do it properly, by quoting them (like 1,2,"<1,2,3>",4,5)... it seems to treat <...> as quoting characters... but it does handle them.
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-13-2005 22:30
for lists of data to be passed though strings i use a set of functions i wrote ages ago (recently named, TightList) list TightListParse(string a) { string b = llGetSubString(a,0,0);//save memory return llParseStringKeepNulls(llDeleteSubString(a,0,0), ,[]); } string TightListDump(list a, string b) {
string c = (string)a; if(llStringLength(b)==1) if(llSubStringIndex(c,b) == -1) jump end; integer d = -llStringLength(b += "|\\/?!@#$%^&*()_=:;~{}[],\n\" qQxXzZ" ; while(1+llSubStringIndex(c,llGetSubString(b,d,d)) && d) ++d; b = llGetSubString(b,d,d); @end; c = "";//save memory return b + llDumpList2String(a, b); }
list TightListTypeParse(string a) { if(llStringLength(a) < 7) return []; //we need a null deliminator string m = "qQxXzZ|\\/?!@#$%^&*()_=:;~{}[],\n\" "; integer d = llStringLength(m); do;while(1+llSubStringIndex(a,llGetSubString(m,--d,d)) && d); m = llGetSubString(m,d,d) + llGetSubString(a,0,5); list b = llParseStringKeepNulls(llDeleteSubString(a,0,5), [],[a=llGetSubString(m,1,1), llGetSubString(m,2,2),llGetSubString(m,3,3),llGetSubString(m,4,4), llGetSubString(m,5,5),llGetSubString(m,6,6)]); if(llList2String(b,0) != "" b = [llGetSubString(m,TYPE_INTEGER,TYPE_INTEGER)] + b; else b = llDeleteSubList(b,0,0); integer c = -llGetListLength(b); list f; do { f = [a=llList2String(b,c + 1)]; //TYPE_STRING || TYPE_INVALID (though we don't care about invalid) if((d = llSubStringIndex(m, llList2String(b,c))) == TYPE_FLOAT) f = [(float)a]; else if(d == TYPE_VECTOR) f = [(vector)a]; else if(d == TYPE_ROTATION) f = [(rotation)a]; else if(d == TYPE_KEY) f = [(key)a]; else if(d == TYPE_INTEGER) f = [(integer)a]; b = llListReplaceList(b, f, c, c+1); }while(c+=2); return b; } string TightListTypeDump(list a, string b) { b += "|\\/?!@#$%^&*()_=:;~{}[],\n\" qQxXzZ"; string c = (string)a; integer d = 0; do if(1+llSubStringIndex(c,llGetSubString(b,d,d))) b = llDeleteSubString(b,d,d); else ++d; while(d<6); b = " " + c = llGetSubString(b,0,5); d = -llGetListLength(a) - 1; integer e; while(++d) c+= llGetSubString(b,e = llGetListEntryType(a,d),e) + llList2String(a,d); return c; }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
12-31-2006 05:37
Any idea why this method won't work for a HUD? I keep getting my avatar's name returned.
string btn_name;
default {
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
12-31-2006 05:42
Any idea why this method won't work for a HUD? I keep getting my avatar's name returned. Prims are linked and script is in root prim, which is not a button. Using this method. default { touch_start(integer total_number) { string name = llGetName(llDetectedLinkNumber(0));
llSay(0,name);//returns avatar's name for me...does the fact that it's a HUD have anything to do with it?
if(name == "Button1") { // Whatever Button1 does... } else if(name == "Button2") { // Whatever Button2 does... } // And so on... } }
|