我正在开发一个具有多个 UDT 的指标。其中一些 UDT 具有在每次更新时动态添加/删除的其他 UDT 数组。
这是我组织代码时遵循的模式:
type TDetail
int oneThing
int anotherThing
//
// This has a collection of TDetail objects.
type TMaster
array<TDetail> details = na
//
// Some sort of factory function.
createMaster() =>
array<TDetail> details = array.new<TDetail>()
TMaster result = TMaster.new(details=details)
(result)
//
// Initialize the master object only once.
var TMaster master = createMaster()
//
// Some logic on every tick...
if (someConditionIsTrue)
TDetail detail = TDetail.new(...properties values go here...)
master.details.push(detail)
但是,我注意到这些项目在刻度之间并没有保留。我错过了什么?
我还尝试使用日志类型库进行“调试”,我注意到数组始终为空,而不是保存以前的 TDetail 对象。
我会尝试在函数作用域之外调用 TMaster.new 或在 createMaster() 中添加 var