2017-01-10 64 views
0

所以我有aNum作为补丁自己的属性,并在我的代码中我有 ask patch 0 -5 [set aNum (aNum - 1)]但修补程序只是将其aNum更改为-1。代码不响应属性更改

我怎样才能确保它需要先前分配的数值,然后从中减去1呢?

谢谢!

回答

0

它符合你的期望。所以问题是,为什么你没有看到你的期望。找到答案称为“调试”。一种简单的调试方法是使用print语句来帮助您检查程序的逻辑。 (另一种方法是使用error来标记意外的程序状态。)例如,

globals [testPatch] 
patches-own [aNum] 

to decrementANum [#patch] 
    ask #patch [set aNum (aNum - 1)] 
end 

to test 
    set testPatch patch 0 -5 
    repeat 5 [ 
    let _before [aNum] of testPatch 
    decrementANum testPatch 
    print (word "before: " _before "; after: " [aNum] of testPatch) 
    ] 
end 

一般来说,写这样一个最小的自包含的例子使一个更好的问题。很可能,您会在尝试制作示例时发现错误。