请问多个语句

时间:2016-02-24 15:15:40

标签: netlogo

允许在ask命令中使用多个语句。我问这个是因为我的代理人没有以正确的方式计算丢失的变量。 Slider-s为零,滑块为10.

[ ask smaller [ set heading [ heading ] of larger forward 0.05 set lost lost + 1 set lostcount lostcount + 1 set color [color] of larger
    if random 100 < slider-s [ if lost > random 100 [ set heading random 360 set lost 0 set color random-float 100]]]]
[ if random 100 < slider
[ ask larger [ set heading [ heading ] of smaller forward 0.05 set lost lost + 1 set lostcount lostcount + 1 set color [color] of smaller
    if random 100 < slider-s [ if lost > random 100 [ set heading random 360 set lost 0 set color random-float 100]]]]]

1 个答案:

答案 0 :(得分:2)

是的,在ask块中有多个命令是有效的。在一行上有多个语句也是有效的(尽管有些不可读)。如果它无效,绿色刻度语法检查器将抛出黄色突出显示的错误消息。

<whatever is the line before - presumably ask some agentset>
  [ ask smaller
    [ set heading [ heading ] of larger
      forward 0.05
      set lost lost + 1
      set lostcount lostcount + 1
      set color [color] of larger
      if random 100 < slider-s
      [ if lost > random 100
        [ set heading random 360
          set lost 0
          set color random-float 100
        ]
      ]
    ]
  ]
  [ if random 100 < slider
    ...
  ]
]

如果您使用上述缩进,您的代码需要更多行,但更容易找到某些类型的错误。特别是,您的代码是否可能错误计算丢失的变量,因为包围不正确并且某些代理通过这些嵌套循环的次数不正确?