2017-07-29 12 views
1

NOBODYランタイムエラーを回避するにはどうすればよいですか?以下はサンプルコードです。これはゼロ除算エラー回避に使用できるコードです。したがって、それはNOBODYエラーを回避するために使用することはできません知っています。しかし、私は他の方法を見つけることができません。以下は、ランタイムエラーメッセージ - > "IFELSE-VALUE予想される入力がTRUE/FALSEであるが、代わりにNOBODYを持つ"です。あなたの助言に感謝します。Netlogo NOBODYを避けるにはどのようにランタイムエラー?

set top ifelse-value (nobody) 
    [ 0 ][ top ] 
    set ts turtles with [speed = 0 and not right-end] 
    set top max-one-of turtles [who] 
    set topx [xcor] of top ; A NOBODY error appears in "of" of this code 
    set L count ts with [xcor > topx] 

答えて

1

ifelse-valueの入力は、レポーターにする必要が戻っいずれかtrueまたはfalse(完全な詳細here。あなたが入力としてnobodyを使用するのであれば、Netlogoは、入力されたか否かを評価しませんnobodyか、それだけでnobodyを読み込む - 。言い換えれば、あなたの入力はtrueまたはfalseのいずれかを返していません

を入力するために、そして、あなたの代わりにブール変数(trueかのいずれかであるものを使用する必要がありますfalse)、等true又はfalseを返しto-report、Netlogoを評価することができる式は、次の例を考えてみます。

to go 

    let x true 
    set top ifelse-value (x) 
    ["x is true"] 
    ["x is NOT true"] 
    print (word "Example 1: " top) 

    set top ifelse-value (this-is-true) 
    ["Reporter returned true"] 
    ["Reporter did not return true"] 
    print (word "Example 2: " top) 

    set x nobody 
    set top ifelse-value (x = nobody) 
    ["x IS nobody"] 
    ["Is NOT nobody"] 
    print (word "Example 3: " top) 

    set x 0 
    set top ifelse-value (x = nobody) 
    ["x IS nobody"] 
    ["x Is NOT nobody"] 
    print (word "Example 4: " top) 

    set top ifelse-value (nobody = nobody) 
    ["nobody = nobody"] 
    ["nobody != nobody"] 
    print (word "Example 5: " top) 

end 

to-report this-is-true 
    report true 
end 
関連する問題