blob: ba6a932d4f637fa6a9a96a2bb5cc9ad75102bf82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?xml version="1.0" encoding="UTF-8" ?>
<class name="bool" category="Built-In Types" version="3.2">
<brief_description>
Boolean built-in type.
</brief_description>
<description>
Boolean is a built-in type. It can represent any data type that is either a true or false value. You can think of it as an switch with on or off (1 or 0) setting . It's often used as part of programming logic in condition statements like [code]if[/code] statements.
[b]Note:[/b] In a code below [code]if can_shoot[/code] is equivalent of [code]if can_shoot == true[/code]. It is good practice to follow the natural spoken language structure when possible. Use [code]if can_shoot[/code] rather than [code]if can_shoot == true[/code] and use [code]if not can_shoot[/code] rather than [code]if can_shoot == false[/code].
[codeblock]
var can_shoot = true
func shoot():
if can_shoot:
# Perform shooting actions here.
[/codeblock]
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.
[codeblock]
var can_shoot = true
func shoot():
if can_shoot and Input.is_action_pressed("shoot"):
create_bullet()
[/codeblock]
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.
[codeblock]
var can_shoot = true
onready var cool_down = $CoolDownTimer
func shoot():
if can_shoot and Input.is_action_pressed("shoot"):
create_bullet()
can_shoot = false
cool_down.start()
func _on_CoolDownTimer_timeout():
can_shoot = true
[/codeblock]
</description>
<tutorials>
</tutorials>
<methods>
<method name="bool">
<return type="bool">
</return>
<argument index="0" name="from" type="int">
</argument>
<description>
Cast an [int] value to a boolean value, this method will return [code]true[/code] if called with an integer value different to 0 and [code]false[/code] in other case.
</description>
</method>
<method name="bool">
<return type="bool">
</return>
<argument index="0" name="from" type="float">
</argument>
<description>
Cast a [float] value to a boolean value, this method will return [code]true[/code] if called with a floating-point value different to 0 and [code]false[/code] in other case.
</description>
</method>
<method name="bool">
<return type="bool">
</return>
<argument index="0" name="from" type="String">
</argument>
<description>
Cast a [String] value to a boolean value, this method will return [code]true[/code] if called with a non-empty string and [code]false[/code] in other case. Examples: [code]bool("False")[/code] returns [code]true[/code], [code]bool("")[/code] returns [code]false[/code].
</description>
</method>
</methods>
<constants>
</constants>
</class>
|