实例化场景后的 _init()
我有两个场景。充当阶级和疾病 s 场景的疾病场景,引发了所有疾病。
dimess.gd
extends Node2D
var disorder_name
var disorder_cause
#-----------------Vitals------------------------
var pulse
var O2
var respirations
var systolic
var diastolic
var temperature
var blood_sugar
func _init(disorder_name, cause, pulse = 0, O2 = 0, respirations = 0, systolic = 0, diastolic = 0, temperature = 0, blood_sugar = 0):
disorder_name = disorder_name
disorder_cause = cause
pulse = pulse
O2 = O2
respirations = respirations
systolic = systolic
diastolic = diastolic
temperature = temperature
blood_sugar = blood_sugar
Disorders.gd
extends Node2D
var disorder = preload("res://Scenes/Disorder.tscn")
func _ready():
var influenza = disorder.instance()
influenza._init(temperature = 5)
我得到
错误(7,30):意外分配。
我不确定如何_Init()
障碍
disororders中的类
能够仅基于dimander分配受影响的参数
实例。 温度= 5
会在人的正常温度中增加5度
I have two scenes. A disorder scene that acts as a class and a disorders scene that initiates all the disorders.
Disorder.gd
extends Node2D
var disorder_name
var disorder_cause
#-----------------Vitals------------------------
var pulse
var O2
var respirations
var systolic
var diastolic
var temperature
var blood_sugar
func _init(disorder_name, cause, pulse = 0, O2 = 0, respirations = 0, systolic = 0, diastolic = 0, temperature = 0, blood_sugar = 0):
disorder_name = disorder_name
disorder_cause = cause
pulse = pulse
O2 = O2
respirations = respirations
systolic = systolic
diastolic = diastolic
temperature = temperature
blood_sugar = blood_sugar
Disorders.gd
extends Node2D
var disorder = preload("res://Scenes/Disorder.tscn")
func _ready():
var influenza = disorder.instance()
influenza._init(temperature = 5)
I get
error(7, 30): Unexpected assign.
I am not sure how to _init()
the Disorder
class in Disorders
to be able to assign only affected params based on the Disorder
instancing.temperature = 5
would add 5 degrees to the person's normal temperature
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gdscript不支持名为参数。
这意味着您不能跳过它们。
如果您真的想使用它,则可以使用词典:
您会这样使用它:
我不知道您会在
原因
上使用什么,但是请注意,它不是可选的。但是,鉴于您的默认值为零,只需在
_Init
之后设置它们要简单得多。因此,_init
可以是:然后:
您当然可以在声明上设置默认值,例如:
在类似的说明上,我想指出 gdscript支持类型。使用它们。
这是一个变体:
这是一个具有值
0
(int)的变体:这是一个具有值
0
(float)的变体:这是一个带有值
的浮点0
:这是一个具有值
0
的INT:这是一个带有值
0
(默认值)的浮子:这是一个具有值
的INT 0
(默认值):这是一个具有值
0
(使用类型推荐)的INT:这是一个带有值
0
的浮点:GDScript do not support named parameters.
Which means you cannot skip them.
If you really want to go for it, you could use a dictionary:
Which you would use like this:
I don't know what you would put on
cause
, but notice it was not optional.However, given that your default values are zero, it is much simpler to just set them after
_init
. So_init
can be:And then:
You can, of course, set default values on the declarations, for example:
On a similar note, I want to point out that GDScript supports types. Use them.
This is a Variant:
This is a Variant with value
0
(int):This is a Variant with value
0
(float):This is a float with value
0
:This is an int with value
0
:This is a float with value
0
(the default value):This is an int with value
0
(the default value):This is an int with value
0
(using type inference):This is a float with value
0
(using type inference):