FSUIPC: Lua Tutorial |
|
Constants and Variables Computers use a lot of values. Many of those values change a lot. Two things we can use to keep track of values are called Constants and Variables. In the Lua language, variables can be "called" anything. It can be made of letters and numbers. They both can be used in mathematical formulas to produce a result. Variables are case-sensitive so x1 is not the same as X1. x = 1 + 2 or x1 = 2 * 2 or Me = 21 * 2 In those examples, x = 3 and x1 = 4 and Me = 42
Constants A Constant is a variable that does not change. In our Lua project with GoFlight, there are many Constants to help us keep track of our modules. Each module has it's own number assignment but instead of trying to remember each one, we "label" them. For example, the GF-45 is number 1, GF-P8 is number 2, GF-T8 is number three ...the GF-TPM is number 16 and the GF-MESM is number 17. Those values won't change so, written into the FSUIPC interface with Lua are the constants GF45=1, GFP8=2, GFT8=3 ... GFTPM=16 & GFMESM=17.
Variables Now we're getting into the meat of programming. If you look at any code, you will find lots of variables. They're used for a lot of things, mostly simple math. A variable is simply a container, a place holder, a bit of short-term memory. If we to do a lot of repetitive math, don't you write down the current value once in a while. That piece of paper just became a variable because the value on it can change. Variables are also classified as Local and Global.
|
|
|