User:Luisa Bourgoin/current projects/gposnp

From Second Life Wiki
Jump to navigation Jump to search

GPOSNP Project

here you will find all things GPOSNP, like current release, locations for additional materials located inworld, and of course the official instructions documented.

what is GPOSNP ? "a controller cube containing instruction lists inside notecards" pretty much summarizes the whole approach

Next class will be at ICE, Wednesday the 28th April of 2010 (lookup ICE LVL inside Events)

additional scripts, slides and notes can be obtained here: ICE classes board🖈

The instruction keywords

the controller box understands reset, start, pause and continue commands from currently active chat channel, which can be unreachable from chatbar. a click onto a running box will stop the program.

the color of the box can be

  1. green for startable, that means not currently running
  2. yellow for program is running, but currently pausing. click does continue
  3. red for emergency stopable by a click, meaning things are running at the moment

the possible keywords for program notecards are, as implemented so far:

channel
channel, chatchannel
switches all communications into chatchannel
timing
timing, timing
the default execution timing of instructions will be set to timing seconds. fractions of seconds are allowed
delay
delay, seconds
sets execution to sleeping some seconds
display
display, text
hoovertext text above controller box
debug
debug
hoovertexting currently executed instruction above controller box. used with slow default timing, this can be very helpfull for observing the activity going on
pause
pause
will set controller into idling, again. this consumes as much power as beeing switched off. it's still listening onto chat commands, on last used channel only. external controller prims can use "continue, controllername" to continue with paused program
chat
chat, text
chats some text
counter
counter, number
initializes the loop counter with number
countdown
countdown
jumps back onto last counter, number definition if the counter still isn't empty
restart
'restart
restartint the program
authorize
authorize, name
adds authorize to the list of people to listen to, or accepting their clicks
public access
public access
sets controller box into public mode, without any user restrictions
volume
volume, number
the controller can chirp some noised, the volume is adjusted by this call onto number percent
playsound
playsound, sound
plays sound which can be any soundfile dropped inside the box

these are inside development

define
define, pattern, substitution
define a variable. the controller can accept chat like
define, controllername, pattern, substitution
from external connections and from there on, all instructions sent out undergo substitutions. this does affect urls on http requests, too. http results can overwrite/re-define variables. this way can be harnessed to store information dynamically, and to communicate stored informations.
it is limited so far, but has been darely needed.
http
http, url
request some more instructions from the network, continueing on notecard afterwards


Controller source code

Current release 2 from 4/30/2010 User:Luisa_Bourgoin/current projects/gposnp/version2

Firstrelease 1 from 4/23/2010 below, includes bugfixes from 1st class

<lsl> // GPOSNP Project - 'general purpose open source notecarded programming' // // initiated by Luisa Bourgoin 7/2008 for useage inside TUi NEO class // fair use only !! this has been created for educational use initially, respect it's origins // you are free to: // * enhance this code, as long as you publish your additions // * use, for builts (even for sale) but keeping this program piece editable // * combine with listener/recieving interactive parts, even closed source ones


// Todo: fix this stuff, and get a new name for it!!1! // add soundfiles preloading? could be done by helper script // caching notes inside memory! getting rid of dataserver events during showtime. Maybe // llLinkeMessage() connected program storage script? // ...preparsing notes. // ...more conditional branching, maybe nameable registers

// release 1 (push on update)

//preferences values: integer broadcast_channel = 0; integer listener; integer internal_part = FALSE;

integer running = FALSE; integer SUSPENDED = -2; float timing_speed = 2.0;

integer access_public = FALSE; list access_names;

string confNoteName = ""; integer notecard_line; integer notecard_lastline; key notecard_lastline_quid; key notecard_request;

integer counter = 0; integer counter_line = 0;

float volume = 1.0; //for sounds integer debug = FALSE;

// if there is anything as in central intelligence, this implements it ... eventually process(string data) {

   list instructions = llCSV2List(data); //split recieved message
   string command = llStringTrim(llList2String(instructions,0), STRING_TRIM_HEAD);
   if(debug) llSetText(data, <1,1,1>, 0.5);
   
   // parse some instructions
   if( llGetSubString(command, 0, 0) == "#" || llGetSubString(command, 0, 1) == "////") {
       //commented out
   }
   else if( command == "display") {
       llSleep(timing_speed);
       llSetText(llGetSubString(data,llStringLength(command)+1,-1), <1,1,1>, 0.5);
   }
   else if( command == "debug") {
       debug = TRUE; //to debug or not debug, that is the question! (shaking knees)
   }
   else if( command == "delay") {
       llSleep(llList2Float(instructions,1));
   }
   else if( command == "timing") {
       timing_speed = llList2Float(instructions,1);
   }
   else if(command == "pause") {
       if(! internal_part) llSetColor(<1,1,0>, ALL_SIDES);
       running = SUSPENDED;
   }
   else if( command == "channel") {
       broadcast_channel = llList2Integer(instructions,1);
       llListenRemove(listener);
       listener = llListen(broadcast_channel,"","","");
   }
   else if( command == "chat") {
       llSleep(timing_speed);
       llSay(0, llGetSubString(data,llStringLength(command)+1,-1));
   }
   else if( command == "counter") {
       counter = llList2Integer(instructions,1);
       counter_line = notecard_line;
   }
   else if( command == "countdown") {
       if(counter-- > 1) {
           notecard_line = counter_line;
       }
   }
   else if( command == "restart") {
       notecard_line = 1;
   }
   else if( command == "authorize") {
       string name = llList2String(instructions,1);
       if(llListFindList(access_names, [name]) < 0) access_names += name;
   }
   else if( command == "public access") {
       access_public = TRUE;
   }
   else if( command == "volume") {
       volume = llList2Float(instructions,1) / 100;
   }
   else if( command == "playsound") {
       llSleep(timing_speed);
       llPlaySound(llList2String(instructions,1), volume);
       //llPreloadSound(llList2String(instructions,1));
   }
   else {
       llSleep(timing_speed);
       if(! internal_part) llSay(broadcast_channel , data); // or llShout()
       else llMessageLinked(LINK_ALL_OTHERS, broadcast_channel, data, NULL_KEY); // or LINK_SET
   }

}

default {

   state_entry()
   {
       llSetText("", <1,1,1>, 0.5);
       if(! internal_part) llSetColor(<0,1,0>, ALL_SIDES);
       access_names = [] + llKey2Name(llGetOwner());
       listener = llListen(broadcast_channel,"","","");
       confNoteName = llGetInventoryName( INVENTORY_NOTECARD ,0 );
       notecard_lastline_quid = llGetNumberOfNotecardLines(confNoteName);
   }
   on_rez(integer start_params)
   {
       llResetScript();
   }
   
   touch_start(integer total_number)
   {
       if(! access_public) if(llListFindList(access_names, [llDetectedName(0)]) < 0) {return;}
       
       if(running || running == SUSPENDED) {
           if(! internal_part) {
               llWhisper(0, "stopping "+confNoteName);
               llSetColor(<0,1,0>, ALL_SIDES);
           }
           running = FALSE;
       }
       else {
           if(! internal_part) {
               llWhisper(0, "running program "+confNoteName);
               llSetColor(<1,0,0>, ALL_SIDES);
           }
           running = TRUE;
           debug = FALSE;
           notecard_line = 1;
           notecard_request = llGetNotecardLine( confNoteName, notecard_line++ - 1 ); // request line
           notecard_lastline_quid = llGetNumberOfNotecardLines(confNoteName); // refresh! otherwise, editing those would kill your patience :)
       }
   }
   
   listen(integer channel, string name, key id, string data)
   {
       if(! access_public) if(llListFindList(access_names, [name]) < 0) {return;}
       
       list instructions = llCSV2List(data); //split recieved message
       string command = llList2String(instructions,0);
       string target = llList2String(instructions,1);
       if(target == llGetObjectName()) {
           if(command == "reset") { llResetScript(); }
           else if(command == "start") {
               if(! internal_part) llSetColor(<1,0,0>, ALL_SIDES);
               running = TRUE;
               debug = FALSE;
               notecard_line = 1;
               notecard_request = llGetNotecardLine( confNoteName, notecard_line++ - 1 ); // request line
               notecard_lastline_quid = llGetNumberOfNotecardLines(confNoteName); // refresh! 
           }
           else if(command == "pause") {
               if(! internal_part) llSetColor(<1,1,0>, ALL_SIDES);
               running = SUSPENDED;
           }
           else if(command == "continue" && running == SUSPENDED) {
               if(! internal_part) llSetColor(<1,0,0>, ALL_SIDES);
               running = TRUE;
               notecard_request = llGetNotecardLine( confNoteName, notecard_line++ - 1 ); // request line
           }
       }
   }
   
   dataserver(key query_id, string data)
   {
       if(query_id == notecard_request && data != EOF && running == TRUE) {
           if(data != "") process(data);
           if((notecard_line -1) >= notecard_lastline) {
               running = FALSE;
               if(! internal_part) llSetColor(<0,1,0>, ALL_SIDES);
           }
           if(running == TRUE) notecard_request = llGetNotecardLine( confNoteName, notecard_line++ - 1 );
       }
       else if(query_id == notecard_lastline_quid) {
           notecard_lastline = (integer)data; //inconsequent!
       }
   }

} //eof </lsl>