Types/bool: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
m (code tags, small grammar changes)
m (formatting)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
A variable type which can have one of two values: <code>true</code> or <code>false</code>. Wikipedia has a comprehensive article on [[wikipedia:Boolean|Booleans]].


A variable type which can have one of two values: <code>true</code> or <code>false</code>. Care must be observed with the concepts of "truthy" and "falsey": different types may behave like <code>true</code> in a boolean context, and <code>nil</code> may act like <code>false</code>, but they are not equal. Especially significant: <code>"true"</code> and <code>"false"</code> are truthy [[Types/string]]s, different from <code>true</code> and <code>false</code>.
== Advanced ==
Booleans used in prototypes can also be be defined by other variable types which are then coerced to boolean values by the game. This type coercion differs from the [https://www.lua.org/manual/5.2/manual.html#2.1 standard Lua truthy/falsy] coercion.


Used in Boolean algebra, which is the foundation of digital logic and processing.  
It is recommended to only use <code>true</code> and <code>false</code>, not the options listed below.


Wikipedia has a comprehensive article on [http://en.wikipedia.org/wiki/Boolean Booleans]
{| class="wikitable"
|-
! Value !! Factorio prototype loading<br>type coercion to boolean !! Lua<br>type coercion to boolean
|-
| <code>""</code> || false || true
|-
| <code>"true"</code> || true || true
|-
| <code>"false"</code> || false || true
|-
| <code>"0"</code> || false || true
|-
| <code>"<any number besides 0 (inside a string)>"</code> || true || true
|-
| <code>"<some random string>"</code> || not coerced, treated as a string || true
|-
| <code>0</code> || false || true
|-
| <code><any number besides 0></code> || true || true
|-
|}

Latest revision as of 13:06, 19 January 2022

A variable type which can have one of two values: true or false. Wikipedia has a comprehensive article on Booleans.

Advanced

Booleans used in prototypes can also be be defined by other variable types which are then coerced to boolean values by the game. This type coercion differs from the standard Lua truthy/falsy coercion.

It is recommended to only use true and false, not the options listed below.

Value  Factorio prototype loading
type coercion to boolean 
Lua
type coercion to boolean
"" false true
"true" true true
"false" false true
"0" false true
"<any number besides 0 (inside a string)>" true true
"<some random string>" not coerced, treated as a string true
0 false true
<any number besides 0> true true