18,700
edits
(→if: don't encourage reader to use bools now that we know how buggy they are in Windows) |
(clarifying that bool variables are broken, not necessarily bool functions; wording; typo fix) |
||
Line 161: | Line 161: | ||
spawn_considered = 1; | spawn_considered = 1; | ||
Here, "spawn_considered" will be set to | Here, "spawn_considered" will be set to 1 regardless of whether the "if" condition was true and spawn_enemy_at_flag() was run. (The indentation has no effect on how the code runs; it's simply to guide the reader.) Though it's nice to save the vertical space by omitting the braces, the danger is in writing something like this: | ||
if (a > 0) | if (a > 0) | ||
Line 433: | Line 433: | ||
==Data types== | ==Data types== | ||
When declaring a variable or a function (more on this under the [[#Functions|Functions]] and [[#Variables|Variables]] sections), you must specify the type of data it contains, accepts, or returns. You can choose from "bool" (can be true | When declaring a variable or a function (more on this under the [[#Functions|Functions]] and [[#Variables|Variables]] sections), you must specify the type of data it contains, accepts, or returns. You can choose from "bool" (can be "true" or "false", but see warning under the "bool" section), "int" (can be any whole number), "float" (a value with a decimal point), or "string" (some text). | ||
var '''int''' x; | var '''int''' x; | ||
Line 448: | Line 448: | ||
===bool=== | ===bool=== | ||
'''(Note: See warning at bottom of this section; | '''(Note: See warning at bottom of this section; the bool type is not recommended for variables.)''' A [[wikipedia:Boolean data type|Boolean]] number has one of two possible states. Thus, a bool can be assigned a value with the keywords "true" and "false". | ||
var bool example = true; | var bool example = true; | ||
Line 461: | Line 461: | ||
if (example eq true) | if (example eq true) | ||
However, Windows Oni will fail to evaluate bare references to | However, Windows Oni will fail to evaluate bare references to bool variables, and testing indicates the possibility of other bugs existing in Windows Oni's handling of bools. Additionally, Bungie West uses virtually no bool variables in Oni's scripts (though they do use built-in functions that return bool values). Since ints are handled much more reliably, it's recommended to use int for variables instead of bool; the values 1 and 0 can represent "true" and "false". | ||
===int=== | ===int=== |