Difference between revisions of "User:Toady Nakamura/Demo Typecast Random Float and Integer"

From Second Life Wiki
Jump to navigation Jump to search
m (finish it)
m (minor tweaks)
 
Line 1: Line 1:
Demonstrates Typecasting... from float & integer to string
Demonstrates Typecasting... from float & integer to string


* Floats are numbers with decimal places (3.1416 or 100.99)
* Floats are numbers with decimal places (3.1416 or 100.99)
* Integers are round numbers (1, 3, 99, 2005)
* Integers are round numbers (1, 3, 99, 2005)
* Strings are anything enclosed in "quotes".
* Strings are anything enclosed in "quotes".


Here we take a number (randomly picked from zero to ten) and show you how to output it as both a float and integer.
Here we take a number (randomly picked from zero to ten) and show you how to output it as both a float and integer.
Line 34: Line 34:
</source>
</source>


*More interesting scripts on my user page! [[User:Toady Nakamura]]
 
Visit my LSL wiki page for my library of simple scripts ! [[User:Toady Nakamura|Toady Nakamura]]

Latest revision as of 14:42, 11 January 2016

Demonstrates Typecasting... from float & integer to string

  • Floats are numbers with decimal places (3.1416 or 100.99)
  • Integers are round numbers (1, 3, 99, 2005)
  • Strings are anything enclosed in "quotes".

Here we take a number (randomly picked from zero to ten) and show you how to output it as both a float and integer.

That's called "type-casting"... changing one type of data to another.

Put this script in a prim and poke the prim to see float values and their corresponding integer values


default
{
    touch_start(integer detected_index)
    {
        float number = llFrand(10.0);  //pick a number between zero and the number in parenthesis

        string numString = (string)number;  // make a string to hold the answer

        llOwnerSay("The float value = " + numString ); // tell owner the value as float


        
        integer numInteger = (integer)number;  // convert the same number already picked

        numString = (string)numInteger; // to a string so it can be "said"

        llOwnerSay("The integer value = " + numString);  // tell owner the value as integer
    }
}


Visit my LSL wiki page for my library of simple scripts ! Toady Nakamura