2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2020-02-01 02:03:48 +01:00
<class name= "bool" version= "4.0" >
2017-09-12 22:42:36 +02:00
<brief_description >
2019-06-22 01:04:47 +02:00
Boolean built-in type.
2017-09-12 22:42:36 +02:00
</brief_description>
<description >
2021-03-18 12:04:28 +01:00
Boolean is a built-in type. There are two boolean values: [code]true[/code] and [code]false[/code]. You can think of it as a switch with on or off (1 or 0) setting. Booleans are used in programming for logic in condition statements, like [code]if[/code] statements.
2020-06-21 07:50:28 +02:00
Booleans can be directly used in [code]if[/code] statements. The code below demonstrates this on the [code]if can_shoot:[/code] line. You don't need to use [code]== true[/code], you only need [code]if can_shoot:[/code]. Similarly, use [code]if not can_shoot:[/code] rather than [code]== false[/code].
2020-07-31 16:07:26 +02:00
[codeblocks]
[gdscript]
var _can_shoot = true
2020-01-13 17:19:03 +01:00
func shoot():
2020-07-31 16:07:26 +02:00
if _can_shoot:
2020-06-21 07:50:28 +02:00
pass # Perform shooting actions here.
2020-07-31 16:07:26 +02:00
[/gdscript]
[csharp]
private bool _canShoot = true;
public void Shoot()
{
if (_canShoot)
{
// Perform shooting actions here.
}
}
[/csharp]
[/codeblocks]
2020-01-13 17:19:03 +01:00
The following code will only create a bullet if both conditions are met: action "shoot" is pressed and if [code]can_shoot[/code] is [code]true[/code].
[b]Note:[/b] [code]Input.is_action_pressed("shoot")[/code] is also a boolean that is [code]true[/code] when "shoot" is pressed and [code]false[/code] when "shoot" isn't pressed.
2020-07-31 16:07:26 +02:00
[codeblocks]
[gdscript]
var _can_shoot = true
2020-01-13 17:19:03 +01:00
func shoot():
2020-07-31 16:07:26 +02:00
if _can_shoot and Input.is_action_pressed("shoot"):
2020-01-13 17:19:03 +01:00
create_bullet()
2020-07-31 16:07:26 +02:00
[/gdscript]
[csharp]
private bool _canShoot = true;
public void Shoot()
{
if (_canShoot & & Input.IsActionPressed("shoot"))
{
CreateBullet();
}
}
[/csharp]
[/codeblocks]
2020-01-13 17:19:03 +01:00
The following code will set [code]can_shoot[/code] to [code]false[/code] and start a timer. This will prevent player from shooting until the timer runs out. Next [code]can_shoot[/code] will be set to [code]true[/code] again allowing player to shoot once again.
2021-03-18 12:04:28 +01:00
[codeblocks]
2020-07-31 16:07:26 +02:00
[gdscript]
var _can_shoot = true
onready var _cool_down = $CoolDownTimer
2020-01-13 17:19:03 +01:00
func shoot():
2020-07-31 16:07:26 +02:00
if _can_shoot and Input.is_action_pressed("shoot"):
2020-01-13 17:19:03 +01:00
create_bullet()
2020-07-31 16:07:26 +02:00
_can_shoot = false
_cool_down.start()
2020-01-13 17:19:03 +01:00
func _on_CoolDownTimer_timeout():
2020-07-31 16:07:26 +02:00
_can_shoot = true
[/gdscript]
[csharp]
private bool _canShoot = true;
private Timer _coolDown;
public override void _Ready()
{
_coolDown = GetNode< Timer> ("CoolDownTimer");
}
public void Shoot()
{
if (_canShoot & & Input.IsActionPressed("shoot"))
{
CreateBullet();
_canShoot = false;
_coolDown.Start();
}
}
public void OnCoolDownTimerTimeout()
{
_canShoot = true;
}
[/csharp]
[/codeblocks]
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
</tutorials>
<methods >
2020-11-10 14:16:20 +01:00
<method name= "bool" qualifiers= "constructor" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2020-11-09 17:46:03 +01:00
<description >
Constructs a default-initialized [bool] set to [code]false[/code].
</description>
</method>
2020-11-10 14:16:20 +01:00
<method name= "bool" qualifiers= "constructor" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "from" type= "bool" />
2017-09-12 22:42:36 +02:00
<description >
2020-11-09 17:46:03 +01:00
Constructs a [bool] as a copy of the given [bool].
2017-09-12 22:42:36 +02:00
</description>
</method>
2020-11-10 14:16:20 +01:00
<method name= "bool" qualifiers= "constructor" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "from" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-06-21 07:50:28 +02:00
Cast a [float] value to a boolean value, this method will return [code]false[/code] if [code]0.0[/code] is passed in, and [code]true[/code] for all other floats.
2017-09-12 22:42:36 +02:00
</description>
</method>
2020-11-10 14:16:20 +01:00
<method name= "bool" qualifiers= "constructor" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "from" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2020-11-09 17:46:03 +01:00
Cast an [int] value to a boolean value, this method will return [code]false[/code] if [code]0[/code] is passed in, and [code]true[/code] for all other ints.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-09-17 17:22:48 +02:00
<method name= "operator !=" qualifiers= "operator" >
<return type= "bool" />
<description >
</description>
</method>
2020-11-10 14:16:20 +01:00
<method name= "operator !=" qualifiers= "operator" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "right" type= "bool" />
2020-11-10 14:16:20 +01:00
<description >
2021-01-06 01:13:11 +01:00
Returns [code]true[/code] if two bools are different, i.e. one is [code]true[/code] and the other is [code]false[/code].
2020-11-10 14:16:20 +01:00
</description>
</method>
<method name= "operator <" qualifiers= "operator" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "right" type= "bool" />
2020-11-10 14:16:20 +01:00
<description >
2021-01-06 01:13:11 +01:00
Returns [code]true[/code] if left operand is [code]false[/code] and right operand is [code]true[/code].
2020-11-10 14:16:20 +01:00
</description>
</method>
2021-09-17 17:22:48 +02:00
<method name= "operator ==" qualifiers= "operator" >
<return type= "bool" />
<description >
</description>
</method>
2020-11-10 14:16:20 +01:00
<method name= "operator ==" qualifiers= "operator" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "right" type= "bool" />
2020-11-10 14:16:20 +01:00
<description >
2021-01-06 01:13:11 +01:00
Returns [code]true[/code] if two bools are equal, i.e. both are [code]true[/code] or both are [code]false[/code].
2020-11-10 14:16:20 +01:00
</description>
</method>
<method name= "operator >" qualifiers= "operator" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "right" type= "bool" />
2020-11-10 14:16:20 +01:00
<description >
2021-01-06 01:13:11 +01:00
Returns [code]true[/code] if left operand is [code]true[/code] and right operand is [code]false[/code].
2020-11-10 14:16:20 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
</methods>
</class>