Rafaela
Rafaela

Reputation: 449

Error: PRECISION expected input to be a number but got the list [-4] instead in NetLogo

I am trying to put precision to 4 decimal places in a result that is stored in the patch. But then try to get this error: PRECISION expected input to be a number but got the list [-4] instead. What am I doing wrong? Thanks in advance

turtles-own [ e x y my-home ]
patches-own [ my-agent, en ]

to test
ask turtles
  [
    set e (x - y)
    ask my-home
    [
      set en [ e ] of my-agent
      set en precision en 2
    ]
 
   die 
  ]
end

Upvotes: 0

Views: 179

Answers (2)

Steve Railsback
Steve Railsback

Reputation: 1736

Clearly, my-agent has been set to an agentset instead of a single agent. In that case, of produces a list instead of a number.

Upvotes: 0

knb
knb

Reputation: 9295

I also cannot reproduce the error, but this works:

turtles-own [ e_ ]
to setup 
  ca
  crt 1
  ask turtles
  [
    set e_ 0.123456789
  ]

end

to go
  ask turtles [
    set e_ (precision e_ 2)
  ]
end

;; now put the standard two buttons on the canvas

;; click "inspect turtle",
;; or type `e_` at the `turtle>` prompt of the command console.

So as user Lena said in her comment, a property e cannot be used, because of the name conflict with the e constant for Natural Logs. The "Check" feature of the Code tab will complain about e but not e_ (or f, or e1...).

Upvotes: 1

Related Questions