首页 > 其他 > 详细

8.引用函数

时间:2018-12-30 11:00:59      阅读:139      评论:0      收藏:0      [点我收藏+]

与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.引用函数

原文:https://www.cnblogs.com/empist/p/10198763.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!