6
edits
m (Update forum links) |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 9: | Line 9: | ||
----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ||
To toggle the Parking brake, use this. Entire code-block shown. Non-repeatable button. (You have to specifically set <repeatable> to true if you want repeatable. It is assumed to be false. | To toggle the Parking brake, use this. Entire code-block shown. Non-repeatable button. (You have to specifically set <repeatable> to true if you want repeatable. It is assumed to be false.) | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<button n="1"> | <button n="1"> | ||
Line 70: | Line 70: | ||
In Nasal, we write "then" as "{" and "endif" as "}". Each "action" (or statement) is terminated by a semicolon: | In Nasal, we write "then" as "{" and "endif" as "}". Each "action" (or statement) is terminated by a semicolon: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (condition) | if (condition) | ||
{ # the opening curly brace means THEN | { # the opening curly brace means THEN | ||
Line 81: | Line 81: | ||
==== An example ==== | ==== An example ==== | ||
Lets say that if x is less than 5 we want to add 2 to it. We write: | Lets say that if x is less than 5 we want to add 2 to it. We write: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { x = x + 2; } | if (x < 5) { x = x + 2; } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The more readable way of writing it is | The more readable way of writing it is | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x = x + 2; | x = x + 2; | ||
Line 93: | Line 93: | ||
And we can even omit the braces if there's only one action: | And we can even omit the braces if there's only one action: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) # no opening brace... | if (x < 5) # no opening brace... | ||
x = x + 2; # ...so the if statement ends at the first semicolon | x = x + 2; # ...so the if statement ends at the first semicolon | ||
Line 99: | Line 99: | ||
If we also want to add 1 to y if the condition is true, we write | If we also want to add 1 to y if the condition is true, we write | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x = x + 2; | x = x + 2; | ||
Line 115: | Line 115: | ||
For example: | For example: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x += 2; # means x = x + 2 | x += 2; # means x = x + 2 | ||
Line 125: | Line 125: | ||
Now lets pretend that we still want to increase x by 2 if it less than 5, and if it is 5 or more we want to add 1 to it. We use else. | Now lets pretend that we still want to increase x by 2 if it less than 5, and if it is 5 or more we want to add 1 to it. We use else. | ||
It looks like this | It looks like this | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x = x + 2; | x = x + 2; | ||
Line 147: | Line 147: | ||
Writing our code properly we get | Writing our code properly we get | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x = x + 2; | x = x + 2; | ||
Line 160: | Line 160: | ||
Easier to understand each condition separately and much less chance of an error. | Easier to understand each condition separately and much less chance of an error. | ||
Our above example would become | Our above example would become | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (x < 5) { | if (x < 5) { | ||
x = x + 2; | x = x + 2; | ||
Line 179: | Line 179: | ||
Lets say that you want something to happen only if the gear is up. But the only property you can read is GearDown. Then you write | Lets say that you want something to happen only if the gear is up. But the only property you can read is GearDown. Then you write | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
if (!GearDown) { | if (!GearDown) { | ||
action; | action; |
edits