Parts of a Variable
- Variable Number - This is the first part of the Variable, it is either expressed as Short, Long, or Float. Short ranges from -32,768 to 32,767, long ranges from -2,147,483,648 to 2,147,483,647, and float is actually not used very often, because it has an extreme amount of inaccuracy, because it cannot go to a specific number, it must round all numbers to a certain number, creating inaccuracies. Long is pretty inaccurate as well, because variables will only read up to 7 digits, and long has 10, that means a 10 digit number will round at the 7th number. The best variable to use is often short. This all seems complicated, I know, so let me explain some things. You may be asking yourself, "what does the number represent Stickmenfalling?" well the number is whatever you desire it to be. In the variable you can assign the number to something the same way you would with a reference. We'll get to that next.
- Variable Name - Variables actually work much like a reference, in fact, a reference is a special type of variable. So all you need to do in order to name a variable accurately, is to, well, name it. Variables, just like references, can have any name, but instead of the sole purpose of making the script more readable, variables are VERY useful for counting, like with time limits and percentage of health. You can declare a variable at any point on the script, as long as it comes before you use it in the actual script. However, it is best to have it just below the name of your script. A good tutorial name for our variable is "MyShortVariable", although you should use a name that is more specific to what you want to accomplish. This is how the variable should look now:
- Congratulations! You just declared a variable, easy as that. But that doesn't mean you understand the variable, does it? Well allow me to explain. With our current variable, we can have ANY number between -32,768 and 32,767, and I mean ANY number. If you wanted to have a countdown from 10, then short is your best number. You should always use short unless you absolutely NEED a number lower than -32,768 or higher than 32,767. Now we need to talk about actually using the variable in our script.
- For this tutorial we are going to assign the variable to a command called GetRandomPercent. As far as I know, there is no short version of this name, like their is for Scriptname (scn) and reference (ref). Anyway, getrandompercent will return a random number between 0 and 99. We'll use our variable to simulate dice:
Short MyShortVariable (We already declared our variable under our script's name, there is no need to do it twice. If it helps, you can rename it "dice")
Set MyShortVariable to 1 + 0.06 * GetRandomPercent (in other words, 1 to 6)
Please keep in mind that I have never actually used variables, as I think they aren't too useful for spell scripts, but they are useful for quests. As such, you should expect a couple of mistakes, if that is the case, either message me, Monkeyuncle (as he is more experienced in this matter), or go here. Thank you for your time, it may be a while for my next tutorial, as I'm going to be trying to learn some POWERFUL stuff .