跳转至

bool

简要描述

布尔值内置类型。

描述

布尔值是内置类型。

**注意:**在if can_shoot下面的代码中,等同于if can_shoot == true。

var can_shoot = true

func Sh​​oot():
    如果can_shoot:
        # Perform shooting actions here.

以下代码仅在同时满足两个条件的情况下才会创建项目符号:按下“拍摄”操作,并且如果can_shoot为true,则将创建子弹。

注意: Input.is_action_pressed(“ shoot”)也是一个布尔值,当按下“ shoot”且` false [

var can_shoot = true

func Sh​​oot():
    如果can_shoot和Input.is_action_pressed(“ shoot”):
        create_bullet()

以下代码会将can_shoot设置为false并启动计时器。

var can_shoot = true
onready var cool_down = $ CoolDownTimer

func Sh​​oot():
    如果can_shoot和Input.is_action_pressed(“ shoot”):
        create_bullet()
        can_shoot =假
        cool_down.start()

func _on_CoolDownTimer_timeout():
    can_shoot = true

方法

返回值类型 方法名称
bool bool(#method-bool)(from: int)
bool bool(#method-bool)(from: float)
bool bool(#method-bool)(from: String)

方法说明

  • bool bool(from: int)

将int值转换为布尔值,如果使用不同于0的整数值和其他情况下的false进行调用,则此方法将返回true。


  • bool bool(from: float)

将float值转换为布尔值,如果以不同的浮点值调用0则返回true,否则返回false。


  • bool bool(from: String)

将String值转换为布尔值,如果使用非空字符串调用此方法,则返回true,在其他情况下,此方法将返回false。