Difference between revisions of "User:ANSI Soderstrom/Misc useful functions"
Jump to navigation
Jump to search
(Created page with "== Leave a comment == * [[User_talk:{{PAGENAME}}|My User Talk about this Page]] == Misc useful functions == Some are useful, some not... <lsl> // modify a string in ANSI-C st…") |
|||
Line 30: | Line 30: | ||
default { | default { | ||
state_entry() { | state_entry() { | ||
llOwnerSay("Hello %s, How %s you? %s is a number.",["Avatar","are",3]); | llOwnerSay(printf("Hello %s, How %s you? %s is a number.",["Avatar","are",3])); | ||
// Output: | // Output: | ||
// Hello Avatar, How are you? 3 is a number. | // Hello Avatar, How are you? 3 is a number. |
Revision as of 03:00, 12 February 2011
Leave a comment
Misc useful functions
Some are useful, some not...
<lsl>
// modify a string in ANSI-C style // returns a string with all replacements for "modifier".... based on the equivalent positions in the list-content string printf(string sentence, list insertation) {
if(llGetListLength(insertation)) { string modifier = "%s"; string new_sentence = sentence; integer i; integer match; for(i=0;i<llGetListLength(insertation);++i) { match = llSubStringIndex(new_sentence,modifier); if(~match) { new_sentence = llDeleteSubString(new_sentence,match,match+1); new_sentence = llInsertString(new_sentence,match,llList2String(insertation,i)); } } return new_sentence; } return "Error, i miss some modifier or the list is empty in: " + sentence;
}
default {
state_entry() { llOwnerSay(printf("Hello %s, How %s you? %s is a number.",["Avatar","are",3])); // Output: // Hello Avatar, How are you? 3 is a number. }
} </lsl>