Difference between revisions of "User:Michel Lemmon/Script Intermedio"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {| width="100%" |- |valign="top"| <div id="box"> ==Script Lezione Script Intermdio Lezione 1 == <div style="padding: 0.5em"> '''Descrizione:''' Si tratta di una lezione Script Intermedio ...)
 
m (added to category)
 
(8 intermediate revisions by one other user not shown)
Line 9: Line 9:
'''Pre-Requisiti:''' Conoscenza script Base e Building
'''Pre-Requisiti:''' Conoscenza script Base e Building


'''Durata Stimata:''' 60 minuti
'''Durata Stimata:''' 90 minuti


'''Nota:''' Trovate qui di seguito le slide della formazione.
'''Nota:''' Trovate qui di seguito le slide della formazione.
Line 31: Line 31:
</div>
</div>
<div id="box">
<div id="box">
==Convenzione==
== Convenzione ==
<div style="padding: 0.5em">
<div style="padding: 0.5em">
Per esigenze di pulizia formale io uso le seguenti convenzioni:
Per esigenze di pulizia formale io uso le seguenti convenzioni:
* le variabili di norma sono prefissate con il tipo (i, l, s, v, f, r) integer, list, string, vector, float, rotation), es. iPippo,fNumber...
* le variabili di norma sono prefissate con il tipo (i, l, s, v, f, r) integer, list, string, vector, float, rotation), es. iPippo,fNumber...
Line 38: Line 39:
* le graffe le metto su nuova linea per chiarezza di dove iniziano e finiscono
* le graffe le metto su nuova linea per chiarezza di dove iniziano e finiscono


if(x==1)
  if(x==1)
{
  {
     <a>
     <a>
}
  }
else
  else
{
  {
     <b>
     <b>
}
  }


</div>
</div>
<div id="box">
<div id="box">
==Debug==
==Debug==
<div style="padding: 0.5em">
<div style="padding: 0.5em">
* uso sempre una funzione debug(string str)
* uso sempre una funzione debug(string str)


debug(string str)
  debug(string str)
{
  {
     if(iDEBUG==1) llSay(10,str);
     if(iDEBUG==1) llSay(10,str);
}
  }


l'uso del canale 10 è legato al fatto che non disturba gli altri in modalità debug. Per "leggere" il debug di un oggetto siffatto basta scriptare quanto segue:
l'uso del canale 10 è legato al fatto che non disturba gli altri in modalità debug. Per "leggere" il debug di un oggetto siffatto basta scriptare quanto segue:
Line 63: Line 63:
* debugger (lo trovate nella box)
* debugger (lo trovate nella box)


default
  default
{
  {
     state_entry()
     state_entry()
     {
     {
Line 73: Line 73:
         llOwnerSay("DEBUG obj: "+objname+": "+str);
         llOwnerSay("DEBUG obj: "+objname+": "+str);
     }
     }
}
  }
 
</div>
</div>
</div>
</div>
Line 104: Line 105:
Oggetto A (Trasmittente):
Oggetto A (Trasmittente):


integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
  integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
integer iDEBUG=1; // abilita debug
  integer iDEBUG=1; // abilita debug
debug(string str)
  debug(string str)
{
  {
     if(iDEBUG==1) llSay(10,str);
     if(iDEBUG==1) llSay(10,str);
}
  }
default
  default
{
  {
     state_entry()
     state_entry()
     {
     {
Line 120: Line 121:
         llSay(iCHANNEL,"Here I am");
         llSay(iCHANNEL,"Here I am");
     }
     }
}
  }


Oggetto B (ricevente):
Oggetto B (ricevente):


integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
  integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
integer iDEBUG=1; // abilita debug
  integer iDEBUG=1; // abilita debug
debug(string str)
  debug(string str)
{
  {
     if(iDEBUG==1) llSay(10,str);
     if(iDEBUG==1) llSay(10,str);
}
  }
default
  default
{
  {
     state_entry()
     state_entry()
     {
     {
Line 144: Line 145:
         }
         }
     }
     }
}
  }
</div>
</div>
</div>
</div>
Line 154: Line 155:
Oggetto A (trasmittente)
Oggetto A (trasmittente)


integer iCHANNEL=-3000;
  integer iCHANNEL=-3000;
integer iDIALOG=-3001; // canale per llDialog
  integer iDIALOG=-3001; // canale per llDialog
integer iDEBUG=1;
  integer iDEBUG=1;
integer iLISTEN=0;
  integer iLISTEN=0;
 
  debug(string str) {}
debug(string str) {}
  default
default
  {
{
     touch_start(integer count)
     touch_start(integer count)
     {
     {
Line 177: Line 177:
         llSay(iCHANNEL,str);
         llSay(iCHANNEL,str);
     }
     }
}
  }


Oggetto B(finestra)
Oggetto B(finestra)


integer iCHANNEL=-3000;
  integer iCHANNEL=-3000;
integer iDEBUG=1;
  integer iDEBUG=1;
debug()....
  debug()....
default
  default
{
  {
     state_entry()
     state_entry()
     {
     {
Line 198: Line 198:
         if(str=="100%") llSetAlpha(0,ALL_SIDES);
         if(str=="100%") llSetAlpha(0,ALL_SIDES);
     }
     }
}
  }
</div>
</div>
</div>
</div>
Line 206: Line 206:
Oggetto A (trasmittente)
Oggetto A (trasmittente)


Oggetto A (trasmittente)
  integer iCHANNEL=-3000; // questo è privato al linkset
integer iCHANNEL=-3000; // questo è privato al linkset
  integer iDIALOG=-3001; // canale per llDialog
integer iDIALOG=-3001; // canale per llDialog
  integer iDEBUG=1;
integer iDEBUG=1;
  integer iLISTEN=0;
integer iLISTEN=0;
  debug(string str) {}
 
  default
debug(string str) {}
  {
default
{
     touch_start(integer count)
     touch_start(integer count)
     {
     {
Line 226: Line 224:
     {
     {
         debug("received the command "+str+" transmitting to the window");
         debug("received the command "+str+" transmitting to the window");
         llListenRemove(iLISTEN);
         llListenRemove(iLISTEN);
         iLISTEN=0;
         iLISTEN=0;
         llMessageLinked(LINK_SET, iCHANNEL, str, "");
         llMessageLinked(LINK_SET, iCHANNEL, str, "");
     }
     }
}
  }


B Oggetto B(finestra)
B Oggetto B(finestra)


integer iCHANNEL=-3000;
  integer iCHANNEL=-3000;
integer iDEBUG=1;
  integer iDEBUG=1;
debug()....
  debug()....
default
  default
{
  {
     state_entry()
     state_entry()
     {
     {
Line 245: Line 242:
     link_message(integer sender, integer num, string str, key id)
     link_message(integer sender, integer num, string str, key id)
     {
     {
        if(num!=iCHANNEL) return;
      if(num!=iCHANNEL) return;
        debug("Received command: "+str);
      debug("Received command: "+str);
        if(str=="0%") llSetAlpha(1,ALL_SIDES);
      if(str=="0%") llSetAlpha(1,ALL_SIDES);
        if(str=="50%") llSetAlpha(0.5,ALL_SIDES);
      if(str=="50%") llSetAlpha(0.5,ALL_SIDES);
        if(str=="100%") llSetAlpha(0,ALL_SIDES);
      if(str=="100%") llSetAlpha(0,ALL_SIDES);
     }
     }
}
  }
</div>
</div>
</div>
</div>
Line 283: Line 280:
==Esercizi da farsi a casa:==
==Esercizi da farsi a casa:==
<div style="padding: 0.5em">
<div style="padding: 0.5em">
* interruttore che accende / spegne una luce.  (si può usare llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 1.0, 10.0
* interruttore che accende / spegne una luce.   
</div>
si può usare llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 1.0, 10.0]);
</div>
<div id="box">
== ==
<div style="padding: 0.5em">
 
</div>
</div>
</div>
</div>
Line 296: Line 288:
{{User:Michel_Lemmon/Michel_Quik_links_it}}
{{User:Michel_Lemmon/Michel_Quik_links_it}}
|}
|}
[[User:Michel Lemmon|Michel Lemmon]] 20:00, 11 march 2008(PST)
[[User:Michel Lemmon|Michel Lemmon]] 20:00, 1 april 2008(PST)
 
[[category:Pagine italiane da wikificare]]

Latest revision as of 13:07, 1 November 2009

Introduzione Corso Script Intermedio 1

  1. Interruttore per accendere/spegnere luci
  2. aprire/chiudere porte
  3. aprire/chiudere finestre
  4. telecomandi e teleport

Scopo

Lo scopo di queste lezioni intermedie è di offrirvi le capacità di poter scriptare degli oggetti per cose che vi servono effettivamente, quindi come supporto alle vostre attività di costruzione.

Convenzione

Per esigenze di pulizia formale io uso le seguenti convenzioni:

  • le variabili di norma sono prefissate con il tipo (i, l, s, v, f, r) integer, list, string, vector, float, rotation), es. iPippo,fNumber...
  • le variabili globali (a parte il prefisso) sono tutte MAIUSCOLE, es. iTIMER...
  • le graffe le metto su nuova linea per chiarezza di dove iniziano e finiscono
 if(x==1)
 {
   <a>
 }
 else
 {
   
 }

Debug

  • uso sempre una funzione debug(string str)
 debug(string str)
 {
   if(iDEBUG==1) llSay(10,str);
 }

l'uso del canale 10 è legato al fatto che non disturba gli altri in modalità debug. Per "leggere" il debug di un oggetto siffatto basta scriptare quanto segue:

  • debugger (lo trovate nella box)
 default
 {
   state_entry()
   {
       llListen(10, "",NULL_KEY,"");
   }
   listen(integer channel,string objname,key id,string str)
   {
       llOwnerSay("DEBUG obj: "+objname+": "+str);
   }
 }

Comunicazione

In comune queste attività hanno il fatto che gli oggetti si parlano "a distanza". Questo vuol dire che 2 o più prim possano scambiarsi informazioni attraverso dei canali di comunicazione.

Parlare vuol dire che l'oggetto A vuole mandare un messaggio M all'oggetto B, che lo "sente" e di conseguenza esegue determinate azioni, eventualmente rispondendo all'oggetto A.

Vi sono molti modi ma i più semplici sono fondamentalmente 2: parlarsi con i canali Say, oppure parlarsi con i canali linked, se gli oggetti sono linkati assieme.

Come si fa a parlarsi con i canali Say:

Gli oggetti A e B si devono mettere d'accordo su un canale comune, possibilmente non utilizzato da altri oggetti. Il canale di solito è:

  • predefinito nei programmi
  • selezionato attraverso una notecard
  • ottenuto indirettamente dal nome dell'oggetto
  • concordato attraverso una procedura di handshake

Noi utilizzeremo inizialmente il sistema predefinito nei programmi, vale a dire specificheremo un canale prefissato.

Esempio di trasmissione elementare

Oggetto A (Trasmittente):

 integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
 integer iDEBUG=1; // abilita debug
 debug(string str)
 {
   if(iDEBUG==1) llSay(10,str);
 }
 default
 {
   state_entry()
   {
       debug("Talking to channel "+(string)iCHANNEL+" click me to make me sending a message");
   }
   touch_start(integer count)
   {
       llSay(iCHANNEL,"Here I am");
   }
 }

Oggetto B (ricevente):

 integer iCHANNEL=-3000; // negativo per non essere utilizzato da avatars
 integer iDEBUG=1; // abilita debug
 debug(string str)
 {
   if(iDEBUG==1) llSay(10,str);
 }
 default
 {
   state_entry()
   {
       llListen(iCHANNEL,"",NULL_KEY,"");
       debug("Listening  to channel "+(string)iCHANNEL);
   }
   listen(integer channel,string objname,key id,string str)
   {
       if(objname=="A")
       {
           llSay(0,"Receiving "+str+" from "+objname);
       }
   }
 }

Finestra che cambia la sua trasparenza

Ora usiamo questo sistema per fare in modo che l'oggetto B (che rappresenta una finestra possa cambiare la sua trasparenza quando riceve da A un comando opportuno. Usiamo un dialogo per controllare il livello di trasparenza.

Oggetto A (trasmittente)

 integer iCHANNEL=-3000;
 integer iDIALOG=-3001; // canale per llDialog
 integer iDEBUG=1;
 integer iLISTEN=0;
 debug(string str) {}
 default
 {
   touch_start(integer count)
   {
       if(iLISTEN!=0) llListenRemove(iLISTEN);
       key avatar=llDetectedKey(0);
       debug("touched, presenting menu");
       llDialog(avatar, "Choose transparency",["0%","50%","100%"],iDIALOG);
       iLISTEN=llListen(iDIALOG,"",avatar,"");
   }
   listen(integer channel,string name,key id,string str)
   {
       debug("received the command "+str+" transmitting to the window");
       llListenRemove(iLISTEN);
       iLISTEN=0;
       llSay(iCHANNEL,str);
   }
 }

Oggetto B(finestra)

 integer iCHANNEL=-3000;
 integer iDEBUG=1;
 debug()....
 default
 {
   state_entry()
   {
       debug("Listening to channel "+(string)iCHANNEL);
       llListen(iCHANNEL,"",NULL_KEY,"");
   }
   listen(integer channel,string name,key id,string str)
   {
       debug("Received command: "+str);
       if(str=="0%") llSetAlpha(1,ALL_SIDES);
       if(str=="50%") llSetAlpha(0.5,ALL_SIDES);
       if(str=="100%") llSetAlpha(0,ALL_SIDES);
   }
 }

A Usando il metodo MessageLinked

Oggetto A (trasmittente)

 integer iCHANNEL=-3000; // questo è privato al linkset
 integer iDIALOG=-3001; // canale per llDialog
 integer iDEBUG=1;
 integer iLISTEN=0;
 debug(string str) {}
 default
 {
   touch_start(integer count)
   {
       if(iLISTEN!=0) llListenRemove(iLISTEN);
       key avatar=llDetectedKey(0);
       debug("touched, presenting menu");
       llDialog(avatar, "Choose transparency",["0%","50%","100%"],iDIALOG);
       iLISTEN=llListen(iDIALOG,"",avatar,"");
   }
   listen(integer channel,string name,key id,string str)
   {
       debug("received the command "+str+" transmitting to the window");
       llListenRemove(iLISTEN);
       iLISTEN=0;
       llMessageLinked(LINK_SET, iCHANNEL, str, "");
   }
 }

B Oggetto B(finestra)

 integer iCHANNEL=-3000;
 integer iDEBUG=1;
 debug()....
 default
 {
   state_entry()
   {
   }
   link_message(integer sender, integer num, string str, key id)
   {
     if(num!=iCHANNEL) return;
     debug("Received command: "+str);
     if(str=="0%") llSetAlpha(1,ALL_SIDES);
     if(str=="50%") llSetAlpha(0.5,ALL_SIDES);
     if(str=="100%") llSetAlpha(0,ALL_SIDES);
   }
 }

Come si vede i due sistemi sono analoghi e presentano vantaggi e svantaggi:

Vantaggi dei canali Say:

  • gli oggetti si possono parlare anche se "molto" distanti (96m),
  • sono abbastanza facili da programmare

Svantaggi dei canali Say:

  • se altri oggetti usano gli stessi canali possono entrare in conflitto
  • producono in generale lag

Vantaggi dei canali MessageLinked:

  • sono molto veloci
  • sono "riservati" (non ci sono problemi di collisione)

Svantaggi dei canali MessageLinked

  • agiscono solo fra oggetti molto vicini e linkati
  • sono un po' più difficili da programmare

Esercizi da farsi a casa:

  • interruttore che accende / spegne una luce.

si può usare llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 1.0, 10.0]);

Michel's Informazioni
Michel Lemmon2.jpg
Click per Ingrandire


Link VTeam

Michel Lemmon 20:00, 1 april 2008(PST)