8.引用函數
阿新 • • 發佈:2018-12-30
itl util default _exit nbsp ase color dsc args
與Python相反,函數不是GDScript中的第一類對象。這意味著它們不能存儲在變量中,不能作為參數傳遞給另一個函數,也不能從其他函數返回。這是出於性能原因。
若要在運行時按名稱引用一個函數(例如,將其存儲在一個變量中,或將其作為參數傳遞給另一個函數),必須使用``call``或``funcref`` 幫助器:
# Call a function by name in one step.
my_node.call("my_function", args)
# Store a function reference.
var my_func = funcref(my_node, "my_function")
# Call stored function reference.
my_func.call_func(args)
Remember that default functions, like _init
, and most notifications, such as _enter_tree
, _exit_tree
, _process
, _physics_process
, etc. are called in all base classes automatically. So there is only a need to call the function explicitly when overloading them in some way.
8.引用函數