Variables | |
Mel has three main types of variables. They are float, int, and string. (There is also vector, but it's not important yet and can be thought of as a group of floats anyway.) A float, or floating point, can hold any real number: 10, 13, 17.519, -81.912, etc. An int is an integer. It can only hold numbers without decimal places:10, 13, 17, -81, etc. A string holds text. They can be numbers or letters, but they are thought of as text: This string is not 81 characters long. To declare a variable simply write the type of variable you want followed by what you want to name it: string $sweetString; You can also tell the string what you want it to contain: string $sweetString = "This string is really sweet." You create numeric variables the same way, except you don't need quotation marks. int $twelve = 32; float $number = 156.891 You can perform any mathematical operations on the numeric types. int $twelve = 12; int $one = 1; int $answer = $twelve + $one; print $answer; 3 You can add strings too, thats the only "mathematical" operation you can do with them though. string $twelve = "twelve"; string $one = "one"; string $answer = $twelve + $one; print $answer; twelveone If you got an error from that second script, read this page about scope. By the way, you can use the print command to see the value of a variable anywhere in a script. |