2016-05-27 191 views
1

請檢查此代碼。哪一部分是錯誤的IfElse嵌套不工作

to catch-lizards 
    let prey one-of lizards-here 
    ifelse prey = "lizard2" 
    [ show "WRONG" ask prey [die] 
    set lifetime = lifetime + hawks-life-gain ] 
    [ifelse droping-tail? = true 
    [ask prey [set shape "lizard2" 
    set lifetime lifetime + hawks-life-gain/4 ] ] 
    [ask prey [die] 
    set lifetime lifetime + hawks-life-gain ] 
    ] 
    ] 
end 

問題在哪裏(顯示「錯誤」)被寫入。該部分不執行。語法不正確?

回答

1

ifelse prey = "lizard2"部分,您比較prey的字符串lizard2。但獵物不是一個字符串,它是一個物體,如shapelifetime

所以你需要問的是獵物的形狀lizard2

更新:檢查獵物的形狀很可能是這樣的:

ask prey [ 
    ifelse shape = "lizard2" [ 
    … 
    ] [ 
    … 
    ] 
] 
+0

我想檢查捕食形狀LIZARD2。那是條件。我怎麼做? PREY是agentset,LIZARD1,LIZARD2是它的形狀。我想在某些條件下交換這些形狀。 –