|
Variables - Numerical Variables |
Top Previous Next |
|
Some tasks in scripting require math operations. To perform these, you need - numbers. That's where numerical variables take place. You'll use 'em as containers for numbers. There are two kinds of numbers you'll store in numerical variables:
If we take this crystal glass and put numbers in it - we get numerical variable ! Just like that glass on image above, important part of numerical variable in MMB is label. Here are some examples of valid labels:
It is recommended to use meaningful & descriptive labels, not too short, not too long - just enough to describe it's contents. If you'll use numerical variable to store number of mouse clicks, label of that variable should be MouseClicks or NoOfMouseClicks. The most important part of this story is - assigning of variable contents.
In MMB script code lines, it is being done by: a) writing label name: glass b) followed by equal sign: = c) and writing content (value) of variable at the end, behind label and equal sign: 5415
All together, MMB code line for assigning of number to numerical variable looks like this: glass=5415
There ! With this line you instructed MMB: "Take a glass and put number 5415 in it." Where will you give that instruction ? In MMB's Script Editor, of course. That's where you'll write your very first MMB code line (if you didn't cheat and skipped all this boring stuff) ;) Very nice. Now, is this all you can do ? Assign fixed numbers and never change 'em again ? Nope ! It is important to have ability of assigning value of one variable to the value of another variable. In other words: if you draw one caricature and give it to your kid:
In MMB script code lines, it is being done by: a) writing label of destination numerical variable (one that accepts value): face2 b) followed by equal sign: = c) and writing label of source numerical variable (one that gives value): face1
All together, MMB code line for assigning of content of one numerical variable to another numerical variable looks like this:: face2=face1 If variable face1 contains number 328, code line above will assign the same value to face2 .
Usage of variable-to-variable approach is recommended when you're planning some math operations on numerical variable and don't want to loose original value. In real life, you would practice on piece of paper before doing anything on original. When scripting in MMB, you don't have to worry about corrupting the original - you simply take another variable and perform changes on it ! Now that's a neat advantage, isn't it ! Talking about math, here are operations you can use in MMB script language:
Notice how many combinations are available here... Math operations with two or more numbers:
a=432/21 SixPack=4+1+1 Math operations with two or more numerical variables: a=b*c Price=Quantity+ItemPrice- Taxes Math operations with combinations of numbers and numerical variables: a=b+42*NumberOfClicks Price=2032*Quantity+83/ NumberOfMembers
All these are valid MMB script code lines ! You will find this combinations very useful in practice. Once calculations on the right side are done, result is assigned to numerical variable on the left and you can use calculated value wherever you want, for example to show it as message: Price=2032*Quantity+83/ NumberOfMembers Message("Price of your order is: ","Price") These two code lines will a) calculate order price, and b) display it using MMB's message box Here's an example of multiple code lines with math operations: days =365 years=100 millenium=1000 NumberOfDays=days*years* millenium Message("Number of days in one millenium: ","NumberOfDays") The result is 36500000 and it's displayed in MMB's message box. Examples mentioned above already show you what numerical variables could be used for. And there are hundreds of other uses, especially when dealing with multimedia subject.
|