Difference between revisions of "User:Chilli Cao/code"
Chilli Cao (talk | contribs) (New page: This is a template I use to start scripts from. It includes most commonly used event handlers and some text output wrappers for debuging, such as s() for say (to comment/uncomment the one ...) |
Chilli Cao (talk | contribs) |
||
Line 1: | Line 1: | ||
This is a template I use to start scripts from. It includes most commonly used event handlers and some | This is a template I use to start scripts from. It includes most commonly used event handlers and some | ||
text output wrappers for debuging, such as s() for say (to comment/uncomment the one needed), st() for settext | text output wrappers for debuging, such as s() for say (to comment/uncomment the one needed), st() for settext, printlist to dump a list and a toggle function. Its meant to delete in opt-out manner whats not needed instead of looking at LSL API on how to do them. | ||
<lsl> | <lsl> | ||
Line 17: | Line 17: | ||
st(string s){llSetText(s, <1,1,1>, 1.0);} | st(string s){llSetText(s, <1,1,1>, 1.0);} | ||
printlist(list l){integer i;for (i=0;i<llGetListLength(l);i++){s("printlist("+(string)i+"):"+llList2String(l,i));} s("printlist Total:"+(string)llGetListLength(l)+" elements");} | printlist(list l){integer i;for (i=0;i<llGetListLength(l);i++){s("printlist("+(string)i+"):"+llList2String(l,i));} s("printlist Total:"+(string)llGetListLength(l)+" elements");} | ||
integer toggle=1;//startup as OFF | |||
toggleme(integer current){ | |||
if (current==1) { toggle=0; | |||
s("SWICH SOMETHING OFF HERE"); | |||
} else {toggle=1; | |||
s("SWICH SOMETHING ON HERE"); | |||
} | |||
} | |||
Line 29: | Line 38: | ||
//llMessageLinked(0,1,"some message linked string",NULL_KEY);//or: LINK_SET LINK_THIS LINK_ROOT LINK_ALL_OTHERS | //llMessageLinked(0,1,"some message linked string",NULL_KEY);//or: LINK_SET LINK_THIS LINK_ROOT LINK_ALL_OTHERS | ||
s("touch_start "+(string)total_number); | s("touch_start "+(string)total_number); | ||
toggleme(toggle);//toggle the toggler | |||
//toggleme(0);//force toggle to ON | |||
} | } | ||
} | } |
Revision as of 11:39, 24 January 2008
This is a template I use to start scripts from. It includes most commonly used event handlers and some text output wrappers for debuging, such as s() for say (to comment/uncomment the one needed), st() for settext, printlist to dump a list and a toggle function. Its meant to delete in opt-out manner whats not needed instead of looking at LSL API on how to do them.
<lsl> //chc-template 0.1 // posted on my wiki page, basicaly as a wiki-lsl-code test //globals: key owner; integer lchan=0;//or any or DEBUG_CHANNEL integer timer_count=0; float PERIOD=0.0; //timer frequency
//debug/helper wrappers: integer verbose=1;s(string s){if (verbose){llOwnerSay(s);}} //integer verbose=1;s(string s){if (verbose){Say(0,s);}} //integer verbose=1;s(string s){if (verbose){llInstantMessage(owner,s);}} st(string s){llSetText(s, <1,1,1>, 1.0);} printlist(list l){integer i;for (i=0;i<llGetListLength(l);i++){s("printlist("+(string)i+"):"+llList2String(l,i));} s("printlist Total:"+(string)llGetListLength(l)+" elements");}
integer toggle=1;//startup as OFF toggleme(integer current){ if (current==1) { toggle=0; s("SWICH SOMETHING OFF HERE"); } else {toggle=1; s("SWICH SOMETHING ON HERE"); } }
default{
state_entry() {s("state_entry: Init");
owner=llGetOwner();
llSetTimerEvent(PERIOD);
llListen(lchan,"",NULL_KEY,"");
}
touch_start(integer total_number) {
if(llDetectedKey(0) == owner){
//llMessageLinked(0,1,"some message linked string",NULL_KEY);//or: LINK_SET LINK_THIS LINK_ROOT LINK_ALL_OTHERS
s("touch_start "+(string)total_number);
toggleme(toggle);//toggle the toggler
//toggleme(0);//force toggle to ON
} } on_rez(integer start_param){ llResetScript(); } changed(integer change){ if(change & CHANGED_OWNER){ llResetScript();} } link_message(integer sender_number, integer number, string message, key id){ s("sendernum:"+(string)sender_number+" num:"+(string)number+" message:"+message+" key:"+(string)id); } dataserver(key requested, string data){ s("datakey:"+requested+" data:"+data); } listen( integer channel, string name, key id, string message ){ if(id == owner){ list args=llParseString2List(message, [" "], []); printlist(args); //string cmd=llList2String(args,0); //float value1=(float)llList2Float(args,1); //if(id == owner){s("chan("+(string)channel+"):"+" cmd: "+cmd+" value1: "+(string)value1);} } } timer(){ s("timer called ("+(string)timer_count+")");timer_count++; } }
</lsl>