【发布时间】:2021-08-01 08:48:46
【问题描述】:
让我们定义 2 个类
A.gd
class_name A
var v = null
func _init(v_):
v = v_
B.gd
class_name B
var v = null
现在,当我尝试使用 str2var/var2str 时,这就是我得到的结果
var a = A.new("aaa")
var b = B.new()
b.v = "bbb"
printt("var2str(a):", var2str(a))
printt("var2str(b):", var2str(b))
printt ("var2str(str2var(var2str(a))):", var2str(str2var(var2str(a))))
printt ("var2str(str2var(var2str(b))):", var2str(str2var(var2str(b))))
输出:
var2str(a): Object(Reference,"script":Resource( "res://Scripts/AI/A.gd"),"v":"aaa")
var2str(b): Object(Reference,"script":Resource( "res://Scripts/AI/B.gd"),"v":"bbb")
var2str(str2var(var2str(a))): Object(Reference,"script":null)
var2str(str2var(var2str(b))): Object(Reference,"script":Resource( "res://Scripts/AI/B.gd"),"v":"bbb")
为什么 str2var(a) 不起作用?
我应该如何解决它?
【问题讨论】:
标签: serialization godot gdscript