Reputation: 161
I defined a set of attributes for some producer agents in the interface as global variables and then assigned them to a list (in the setup) which is also global and the agents will use its content.
The problem is that I cannot plot them.
Defined in the interface as global variables : p1-size = 9, p2-size = 13, p3-size = 14.5, p1-rate = 80, p2-rate = 50, p3-rate = 98
to setup
ca ; clear-all
reset-ticks
file-close-all
setup-patches
create-prod ; create producers
set size-set ((list p1-size p2-size p3-size))
set rate-set ((list p1-rate p2-rate p3-rate))
I want to plot and monitor how the rates changes, and I encounter an error by defining this :
plot item 0 size-set
Size-set is global, but the error says "ITEM expected to be a string or list but got the number 0 instead.
I'd appreciate any help regarding this.
Thanks,
Upvotes: 1
Views: 519
Reputation: 14972
The reset-ticks
primitive has the side effect of updating the plots. In your code, you're calling reset-ticks
before setting the value of size-set
, so at the time your plot calls plot item 0 size-set
, your size-set
global still has its default value of 0
.
Two potential solutions:
Move reset-ticks
to the end of your setup
procedure. That way, size-set
will be correctly initialized when your plot is updated. Unless you have a very particular reason to do otherwise, this is the solution you should choose. It is the standard in NetLogo to call reset-ticks
only at the end of setup
.
You shouldn't do this unless you have a good reason, but you could also have some sort of "guard condition" in your plotting statement: if is-list? size-set [ plotxy ticks item 0 size-set ]
. Notice the use of plotxy
instead of plot
to ensure that you're still plotting at the correct x position even if your guard condition causes you to skip some ticks.
Upvotes: 4