Difference between revisions of "A Basic LSL Tutorial/it"

From Second Life Wiki
Jump to navigation Jump to search
Line 119: Line 119:
llSetText, la cui sintassi è: llSetText(string testo, vector colore, float alfa-trasparenza).
llSetText, la cui sintassi è: llSetText(string testo, vector colore, float alfa-trasparenza).
Fondamentalmente se scrivi llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,1);
Fondamentalmente se scrivi llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,1);
Apparirà CIAO, PUOI LEGGERE QUESTO in rosso. Alfa è la trasparenza
Apparirà CIAO, PUOI LEGGERE QUESTO in rosso. Alfa è la trasparenza.


if you did llSetText("HELLO CAN YOU READ THIS",<1,0,0>,0); you wouldn't be able to see it.
Se avessi fatto llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,0); non riusciresti a vederlo.
0 = high transparency, 0.5 = in the middle, 1 = no transparency.
0 = completamente trasparente, 0.5 = semitrasparente, 1 = nessuna trasparenza.
Your script should look something like this:
Il tuo script dovrebbe apparire così:


<lsl>
<lsl>
Line 130: Line 130:
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Hello, Avatar!");
         llSay(0, "Ciao, Avatar!");
     }
     }


     touch_start(integer total_number)
     touch_start(integer numero)
     {
     {
     llSetText("HELLO CAN YOU READ THIS",<1,0,0>,1);     
     llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,1);     
     }
     }
}
}
</lsl>
</lsl>


'''TASK 5''':
'''Compito N. 5''':
-------
-------
Now that you understand alpha we shall make our object disappear!
Adesso che capisci l'alfa faremo scomparire il nostro oggetto!
To do this we will use the function llSetAlpha, its layout is llSetAlpha(float alpha, integer face).
Per farlo useremo la funzione llSetAlpha, la cui sintassi è llSetAlpha(float alfa, integer faccia).
llSetAlpha(0, ALL_SIDES); would make all the faces of the object transparent.
llSetAlpha(0, ALL_SIDES); renderà tutte le facce dell'oggetto trasparenti.
If it was a linked object you could use llSetLinkAlpha, which its layout is
Se fosse un oggetto linkato dovresti usare llSetLinkAlpha, la cui sintassi è
llSetLinkAlpha(integer linknumber, float alpha, integer face).
llSetLinkAlpha(integer numerolink, float alfa, integer faccia).
Your script should look something like this:
Il tuo script dovrebbe essere così:


<lsl>
<lsl>
Line 154: Line 154:
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Hello, Avatar!");
         llSay(0, "Ciao, Avatar!");
     }
     }


     touch_start(integer total_number)
     touch_start(integer numero)
     {
     {
    llSetAlpha(0, ALL_SIDES);     
        llSetAlpha(0, ALL_SIDES);     
     }
     }
}
}
Line 165: Line 165:




'''Task 6''':
'''Compito N. 6''':
-------
-------
Lets try make our object texture itself, to do this we will use the function llSetTexture, its
Adesso facciamo in moo che il nostro oggetto si cambi la texture, per farlo useremo la funzione llSetTexture, la
layout is llSetTexture(string texture, integer face).You can do this two ways, you can place a
cui sintassi è llSetTexture(string texture, integer faccia). Puoi farlo in due modi: puoi mettere la texture dentro l'oggetto
texture inside the object or use a UUID. To make it change to a texture you have placed inside
oppure usare una UUID. Per cambiare la texture che hai messo dentro l'oggetto
the object, do it like this llSetTexture("NAME OF TEXTURE", ALL_SIDES);
fai così: llSetTexture("NOME DELLA TEXTURE", ALL_SIDES);
If you want to use a UUID, find a texture in your inventory, right click it > copy asset UUID,
Se vuoi usare una UUID, trova una texture (full permission) nel tuo inventory, fai tasto destro > copy asset UUID,
then paste the UUID in the "" so it looks like this
e quindi fai incolla della UUID nelle virgolette "" in modo che diventi
llSetTexture("j4m3s000-0000-0000-0000-b3n3d3k00000", ALL_SIDES);
llSetTexture("j4m3s000-0000-0000-0000-b3n3d3k00000", ALL_SIDES);
If it was a linked object you could use llSetLinkTexture, which its layout is
Se fosse un oggetto linkato dovresti usare llSetLinkTexture, la cui sintassi è
llSetLinkTexture(integer linknumber, string texture, integer face);
llSetLinkTexture(integer numerolink, string texture, integer faccia);
Your script should look something like this:
Il tuo script dovrebbe essere così:


<lsl>
<lsl>
Line 183: Line 183:
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Hello, Avatar!");
         llSay(0, "Ciao, Avatar!");
     }
     }


     touch_start(integer total_number)
     touch_start(integer numero)
     {
     {
     llSetTexture("NAME OF TEXTURE", ALL_SIDES);     
     llSetTexture("NOME DELLA TEXTURE", ALL_SIDES);     
     }
     }
}
}
</lsl>
</lsl>


'''Task 7''':
'''Compito N. 7''':
-------
-------
Now lets move onto something more tricky, as you understand a bit about keys we will make out object
Adesso facciamo qualcosa di più complesso. Se capite il concetto di "chiave UUID dell'avatar" faremo un oggetto che
only respond when the owner clicks the object, this is called a if statement.
obbedisce solo "SE" viene cliccato dal proprietario. Questa cosa viene chiamata istruzione IF (che vuol dire "SE").
To do this we will need to use the functions llGetOwner() and llDetectedKey(0);, llGetOwner will
Per farlo abbiamo bisogno di usare la funzione llGetOwner() e llDetectedKey(0);, llGetOwner restituisce
return your key UUID and llDetectedKey(0) when put under the touch event will return the key of who is
la UUID della vostra chiave e llDetectedKey(0) se messa nell'evento di "touch" restituisce la chiave di chi sta toccando il tuo oggetto.
clicking/touching your object. So firstly lay it out your script like this:
Per cominciare scrivi il tuo script in questo modo:


<lsl>
<lsl>
Line 206: Line 206:
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Hello, Avatar!");
         llSay(0, "Ciao, Avatar!");
     }
     }


     touch_start(integer total_number)
     touch_start(integer numero)
     {
     {
    if (llDetectedKey(0) == llGetOwner())
      if (llDetectedKey(0) == llGetOwner())
    {
      {
        llSay(0, "Owner Touched.");
          llSay(0, "Mi ha toccato il mio proprietario.");
    }
      }
      
      
     }
     }
Line 220: Line 220:
</lsl>
</lsl>


If you want it to do something when someone else other than the owner touches it, use a else statement.
Se invece vuoi fare qualcosa d'altro quando qualcuno diverso dal proprietario lo tocca, devi usare l'istruzione
You can do this by, laying out your script like this:
else ("altrimenti" in inglese).
Ad esempio nel seguente modo:


<lsl>
<lsl>
Line 228: Line 229:
     state_entry()
     state_entry()
     {
     {
         llSay(0, "Hello, Avatar!");
         llSay(0, "Ciao, Avatar!");
     }
     }


     touch_start(integer total_number)
     touch_start(integer numero)
    {
    if (llDetectedKey(0) == llGetOwner())
    {
        llSay(0, "Owner Touched.");
    }
    else
     {
     {
    llSay(0, "Someone Else Touched.");
      if (llDetectedKey(0) == llGetOwner())
    }
      {
          llSay(0, "Mi ha toccato il mio proprietario.");
      }
      else
      {
          llSay(0, "Non sei il mio proprietario!");
      }
     }
     }
}
}
</lsl>
</lsl>


'''Task 8''':
'''Compito N. 8''':
-------
-------
Now lets try make a object do something when you say something, to do this
Now lets try make a object do something when you say something, to do this

Revision as of 11:22, 8 July 2009

Tutorial di base su LSL. Fatto da James Benedek Tradotto in italiano da Salahzar Stenvaag



Quando crei uno script verrà sempre creato questo abbozzo iniziale: <lsl> default {

   state_entry()
   {
       llSay(0, "Hello, Avatar!");
   }
   touch_start(integer total_number)
   {
       llSay(0, "Touched.");
   }

} </lsl>

Questo script dice semplicemente "Hello, Avatar!" sul canale pubblico che è lo 0, e quindi dirà "Touched." sul canale pubblico quando un avatar lo tocca o lo clicca.

Come correggere gli errori?


Se in qualunque momento hai un errore mentre stai scriptando, normalmente hai dimenticato un ";" alla fine di una funzione oppure una "{" oppure "}" prima o dopo un evento. Questa è la causa più comune (errore sintattico). A volte succedono anche altre cose.

Comprensione base dei termini:


Una funzione è mostrata in rosso ((ed è un comando da far eseguire al programma come llSay))

Un "event" è mostrato in blu chiaro ((ed è una situazione che scatta ad esempio al tocco))

Una "string" sono dei caratteri e deve essere racchiusa fra apicetti "", come ad esempio "ciao eva!".

Un "integer" è un numero senza virgola come ad esempio 1

Un "vector" sono 3 numeri scritti come <0,0,0>, e può rappresentare un colore oppure una posizione.

Un "float" è un numero decimale come 1.0, usato spesso negli alfa e per i calcoli.

Una "key" è un numero UUID casuale generato dai laboratori linden come ad esempio d77442ea-5acc-4ed3-bbb4-1f2bf2c31bb6.

TRUE e FALSE, FALSE è lo stesso di 0, e TRUE è uguale all'intero 1.


Compito N. 1:


Cominciamo con il fare un semplice esercizio, facciamo una scatola che dica qualcosa d'altro quando la cliccate, per farlo basta che cambiate la scritta "llSay(0, "Touched.");". Modifica solo all'interno delle virgolette "". La sintassi di llSay è come segue: llSay(canale, "cosa dire");

llSay non è l'unica funzione che può usare l'oggetto per comunicare, puoi anche provare:

llShout(canale, "URLA QUESTO"); llWhisper(canale, "sussurra questo"); llOwnerSay("parla solo al proprietario"); llRegionSay(canale, "dì questo a tutta la regione"); // solo con canale diverso da zero


Compito N. 2:


Adesso aggiungiamo delle informazioni successive per spiegare cosa fa questo script, puoi carlo aggiungendo // e qualunque altra cosa dopo le sue barre appariranno in arancio, e rappresentano un commento. Il tuo script apparirà come segue:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!"); // dì Ciao alla partenza
   }
   touch_start(integer total_number)
   {
       llSay(0, "Toccato."); // dì toccato quanto qualcuno ti tocca
   }

} </lsl>

Compito N. 3:


Adesso proviamo a fargli cambiare il colore quando qualcuno lo tocca, la funzione di cui abbiamo bisogno è llSetColor, la sua sintassi è la seguente llSetColor(vector colore, integer faccia); questo significa in pratica che se io voglio che il cubo sia rosso devo usare il vettore <1,0,0>, verde, <0,1,0>, blu <0,0,1>. Per la mappa di tutti colori vedi il link qui sotto:

http://www.lslwiki.net/lslwiki/wakka.php?wakka=color

Se fosse un oggetto linkato devi usare llSetLinkColor, la cui sintassi è llSetLinkColor(integer numerolink, vector colore, integer faccia). Il tuo script dovrebbe essere simile a questo:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
   llSetColor(<1,0,0>, ALL_SIDES);
   }

} </lsl>


Compito N. 4:


Adesso facciamo in modo da visualizzare un testo SOPRA, potete farlo con la funzione llSetText, la cui sintassi è: llSetText(string testo, vector colore, float alfa-trasparenza). Fondamentalmente se scrivi llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,1); Apparirà CIAO, PUOI LEGGERE QUESTO in rosso. Alfa è la trasparenza.

Se avessi fatto llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,0); non riusciresti a vederlo. 0 = completamente trasparente, 0.5 = semitrasparente, 1 = nessuna trasparenza. Il tuo script dovrebbe apparire così:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
   llSetText("CIAO, PUOI LEGGERE QUESTO",<1,0,0>,1);    
   }

} </lsl>

Compito N. 5:


Adesso che capisci l'alfa faremo scomparire il nostro oggetto! Per farlo useremo la funzione llSetAlpha, la cui sintassi è llSetAlpha(float alfa, integer faccia). llSetAlpha(0, ALL_SIDES); renderà tutte le facce dell'oggetto trasparenti. Se fosse un oggetto linkato dovresti usare llSetLinkAlpha, la cui sintassi è llSetLinkAlpha(integer numerolink, float alfa, integer faccia). Il tuo script dovrebbe essere così:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
       llSetAlpha(0, ALL_SIDES);     
   }

} </lsl>


Compito N. 6:


Adesso facciamo in moo che il nostro oggetto si cambi la texture, per farlo useremo la funzione llSetTexture, la cui sintassi è llSetTexture(string texture, integer faccia). Puoi farlo in due modi: puoi mettere la texture dentro l'oggetto oppure usare una UUID. Per cambiare la texture che hai messo dentro l'oggetto fai così: llSetTexture("NOME DELLA TEXTURE", ALL_SIDES); Se vuoi usare una UUID, trova una texture (full permission) nel tuo inventory, fai tasto destro > copy asset UUID, e quindi fai incolla della UUID nelle virgolette "" in modo che diventi llSetTexture("j4m3s000-0000-0000-0000-b3n3d3k00000", ALL_SIDES); Se fosse un oggetto linkato dovresti usare llSetLinkTexture, la cui sintassi è llSetLinkTexture(integer numerolink, string texture, integer faccia); Il tuo script dovrebbe essere così:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
   llSetTexture("NOME DELLA TEXTURE", ALL_SIDES);    
   }

} </lsl>

Compito N. 7:


Adesso facciamo qualcosa di più complesso. Se capite il concetto di "chiave UUID dell'avatar" faremo un oggetto che obbedisce solo "SE" viene cliccato dal proprietario. Questa cosa viene chiamata istruzione IF (che vuol dire "SE"). Per farlo abbiamo bisogno di usare la funzione llGetOwner() e llDetectedKey(0);, llGetOwner restituisce la UUID della vostra chiave e llDetectedKey(0) se messa nell'evento di "touch" restituisce la chiave di chi sta toccando il tuo oggetto. Per cominciare scrivi il tuo script in questo modo:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
      if (llDetectedKey(0) == llGetOwner())
      {
          llSay(0, "Mi ha toccato il mio proprietario.");
      }
   
   }

} </lsl>

Se invece vuoi fare qualcosa d'altro quando qualcuno diverso dal proprietario lo tocca, devi usare l'istruzione else ("altrimenti" in inglese). Ad esempio nel seguente modo:

<lsl> default {

   state_entry()
   {
       llSay(0, "Ciao, Avatar!");
   }
   touch_start(integer numero)
   {
      if (llDetectedKey(0) == llGetOwner())
      {
          llSay(0, "Mi ha toccato il mio proprietario.");
      }
      else
      {
          llSay(0, "Non sei il mio proprietario!");
      }
   }

} </lsl>

Compito N. 8:


Now lets try make a object do something when you say something, to do this we will have to use a llListen function, its layout is this llListen(integer channel, string name, key id, string msg); We will firstly place this under the state_entry() event. In this task we will just make it use the public channel, which is 0, and we will make it listen to only you, which requires the llGetOwner() function we used previously. We will then need to use a listen event, its layout is like this listen(integer channel, string name, key id, string message) {, replace the touch event with this. we will then make the object annoy you by it saying "Really?" whenever you type something XD This will involve using a llSay like we used in task 1. Your script should look something like this:

<lsl> default {

   state_entry()
   {
       llListen(0,"",llGetOwner(),"");
   }
   
   listen(integer channel, string name, key id, string message)
   {
       llSay(0,"Really?");
   }

} </lsl>

To make it only listen for commands not on the public channel, which will be more secret and which is less laggy in complex scripts, you can do this by changing the integer 0 to something like 99, this time use a llOwnerSay instead of a llSay, which should make it secret. Your script should look something like this:

<lsl> default {

   state_entry()
   {
       llListen(99,"",llGetOwner(),"");
   }
   
   listen(integer channel, string name, key id, string message)
   {
       llOwnerSay("Really?");
   }

} </lsl>

To chat in another channel, just type in the chat bar /channel before you type something, in this case it will be "/99 hello" for example.To make it do only certain stuff when you say certain commands we will have to use a if statement, like before but this time we will have to check if the message equals the command, if (message == "Your Command Here"). Your script should look something like this:

<lsl> default {

   state_entry()
   {
       llListen(99,"",llGetOwner(),"");
   }
   
   listen(integer channel, string name, key id, string message)
   {
   if (message == "hello")
   {
       llOwnerSay("Hello to you too!");
   }
   else
   {
       llOwnerSay("INVALID COMMAND");
   }
   }

} </lsl>

To learn more about llListen take a look at:

https://wiki.secondlife.com/wiki/llListen

TASK 9:


Now lets experiment with vectors, and make your object move non physically, to do this we will need to use the function llSetPos, its layout is llSetPos(vector pos); We will also use llGetPos() so we can make it move +1 of its current position. Place the llSetPos function under a touch event with a vector <0,0,1> + llGetPos();. Your script should look something like this:

<lsl> default {

   state_entry()
   {
       llSay(0, "Hello, Avatar!");
   }
   touch_start(integer total_number)
   {
   llSetPos(llGetPos() + <0,0,1>);
   }

} </lsl>

A position vector layout is in the format x,y,z, so <0,0,1> will make it go up 1m. to learn more take a look at:

https://wiki.secondlife.com/wiki/llSetPos

TASK 10:


Like when editing a object you can make it Phantom, Physical... You can also do this with scripting, the function you have to use to do this is llSetStatus, its layout is llSetStatus(integer status, integer value);, so if i wanted to make my object go physical the integer status would be STATUS_PHYSICS or 1, if i wanted to make my object go phantom i would use STATUS_PHANTOM or 16. Your script should look something like this:

<lsl> default {

   state_entry()
   {
       llSetStatus(STATUS_PHYSICS, TRUE);
   }

} </lsl>


You now know pretty much the basics of scripting, but there are still many more functions to use and experiment with yet!!!!!! To know more functions and what they do, take a look at these links below:

http://wiki.secondlife.com/wiki/LSL_Portal

http://www.lslwiki.net/lslwiki/wakka.php?wakka=HomePage

http://rpgstats.com/wiki/index.php?title=Main_Page