Boolean: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Добавление языков) |
||
(6 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
A ''boolean'' or ''bool'' is a datatype whose value can be either ''true'' or ''false''. These are often returned by functions to indicate whether the operation was successful or not. | A ''boolean'' or ''bool'' is a datatype whose value can be either ''true'' or ''false''. These are often returned by functions to indicate whether the operation was successful or not. | ||
Using the lua functions tostring() and type() can help you to find out what datatype something is: | |||
<syntaxhighlight lang="lua"> | |||
local theReturn = isPedDead(getRandomPlayer()) | |||
outputChatBox("The return was: "..tostring(theReturn)) -- Will say: "true" or "false" | |||
outputChatBox("The datatype of this return was: "..type(theReturn)) -- Will say "boolean" | |||
</syntaxhighlight> | |||
==Reversing bools== | |||
<syntaxhighlight lang="lua"> | |||
bool = true | |||
-- if you want to reverse it you can either do | |||
bool = false | |||
-- or | |||
bool = not bool | |||
</syntaxhighlight> | |||
[[Category:Scripting Concepts]] | [[Category:Scripting Concepts]] | ||
[[en:Boolean]] | |||
[[ru:Boolean]] | [[ru:Boolean]] | ||
[[de:Boolean]] | |||
[[hu:Boolean]] |
Latest revision as of 19:45, 12 April 2021
A boolean or bool is a datatype whose value can be either true or false. These are often returned by functions to indicate whether the operation was successful or not.
Using the lua functions tostring() and type() can help you to find out what datatype something is:
local theReturn = isPedDead(getRandomPlayer()) outputChatBox("The return was: "..tostring(theReturn)) -- Will say: "true" or "false" outputChatBox("The datatype of this return was: "..type(theReturn)) -- Will say "boolean"
Reversing bools
bool = true -- if you want to reverse it you can either do bool = false -- or bool = not bool