Difference between revisions of "Variables Example"
Jump to navigation
Jump to search
Eyana Yohkoh (talk | contribs) (New page: {{LSL Header}} ===Variables Example=== This is an example to show the basic use of variables. --~~~~ <pre> // this script will add 1 to x every other time it is touched. integer x = 8; ...) |
Huney Jewell (talk | contribs) m (Avoid line overflow) |
||
Line 29: | Line 29: | ||
{ | { | ||
x = x + 1; // adding one to x here | x = x + 1; // adding one to x here | ||
llSay( 0, "1 added to x. x is now: " + (string)x ); | |||
llSay( 0, "1 added to x. x is now: " + (string)x ); | |||
// this will make the object say the value of x. | |||
y = TRUE; // since this started with y being FALSE, now it's time | y = TRUE; // since this started with y being FALSE, now it's time | ||
// to make it TRUE so the next time it's clicked it does | // to make it TRUE so the next time it's clicked it does | ||
Line 37: | Line 38: | ||
else if ( y == TRUE ) // do this stuff is y is TRUE | else if ( y == TRUE ) // do this stuff is y is TRUE | ||
{ | { // object says this | ||
llSay( 0, "nothing added to x this time. x is still: " + (string)x ); | llSay( 0, "nothing added to x this time. x is still: " + (string)x ); | ||
y = FALSE; // since nothing was added this time then set y back to FALSE | |||
// so something gets added next time. | // so something gets added next time. | ||
} | } |
Revision as of 07:19, 7 September 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Variables Example
This is an example to show the basic use of variables. --Eyana Yohkoh 19:24, 27 August 2007 (PDT)
// this script will add 1 to x every other time it is touched. integer x = 8; // this makes an integer set to the value of eight when the script starts integer y = FALSE; // you can set integers to TRUE or FALSE too // in this example, y is going to be used to see if the last time the object // was clicked 1 was added to x. // basically by setting y to TRUE and FALSE the script will be able to add one // to x every other time default { state_entry() // we'll just have the script say the value of x when it loads { llSay( 0, "x has a value of: " + (string)x ); } touch_start(integer total_number) { if ( y == FALSE ) // first time clicked y would be false so that's when 1 // should be added to x { x = x + 1; // adding one to x here llSay( 0, "1 added to x. x is now: " + (string)x ); // this will make the object say the value of x. y = TRUE; // since this started with y being FALSE, now it's time // to make it TRUE so the next time it's clicked it does // something different. } else if ( y == TRUE ) // do this stuff is y is TRUE { // object says this llSay( 0, "nothing added to x this time. x is still: " + (string)x ); y = FALSE; // since nothing was added this time then set y back to FALSE // so something gets added next time. } } }