User:Toady Nakamura/Demo Typecast Random Float and Integer
< User:Toady Nakamura
Jump to navigation
Jump to search
Revision as of 12:21, 5 July 2012 by Toady Nakamura (talk | contribs) (added typecast demo script for my students)
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
<lsl>
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 }
} </lsl>