How to set up a counter

22 views
Skip to first unread message

jcamer...@gmail.com

unread,
May 8, 2020, 2:39:49 PM5/8/20
to netlogo-users
I need to use a counter, either to count time steps since an event has happened or to count the number of times an event has happened, and I can't figure out how to set one up. I'd also like to pass a counter to a function(similar to python or other more general coding languages).

Charles Lassiter

unread,
May 8, 2020, 3:44:43 PM5/8/20
to jcamer...@gmail.com, netlogo-users
From what you've written, a simple solution would be to add a global variable and then set it to add one whenever the event happens.

globals [counter]

to setup
...
set counter 0
...
end

to do-the-thing
...
event-you-want-to-count
set counter counter + 1
end

It'll look different depending on what you're trying to count, but that's the basic idea. If you want to use it in a function, plug 'counter' into it. If you don't want to keep track of the counts by means of a variable you could write a reporter, but you'd need to give some more detail for suggestions (at least from me).




On Fri, May 8, 2020 at 11:39 AM <jcamer...@gmail.com> wrote:
I need to use a counter, either to count time steps since an event has happened or to count the number of times an event has happened, and I can't figure out how to set one up. I'd also like to pass a counter to a function(similar to python or other more general coding languages).

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/983cc8a6-0d91-478d-b3da-5c29d0a9e8d6%40googlegroups.com.


--
Charles Lassiter
Philosophy Department
Gonzaga University
502 E. Boone Avenue
Box AD 47
Spokane, WA 99258
Reply all
Reply to author
Forward
0 new messages