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

From Second Life Wiki
Jump to navigation Jump to search
m (minor edit)
m (fix <source lang="lsl2"> </source> error which was causing page to display incorrectly)
Line 12: Line 12:




<lsl>
<source lang="lsl2">
default
default
{
{
Line 32: Line 32:
     }
     }
}
}
</lsl>
</source>


*Toadified July 5, 2012 --[[User:Toady Nakamura|Toady Nakamura]]
*Toadified July 5, 2012 -- More interesting scripts on my user page! [[User: Toady Nakamura]]

Revision as of 15:54, 30 July 2015

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
    }
}