can i launch go-forever from code?

19 views
Skip to first unread message

wade.s...@gmail.com

unread,
Jun 23, 2022, 7:42:53 AM6/23/22
to netlogo-users
I'm trying to figure out how to start and stop the GO-FOREVER loop from code instead of pushing the usual button.  The "go-forever" button does something subtle besides just repeating the GO code.

I suspect that the Go-Forever loop does something like make one pass of the go loop, then check for events like queued button presses and deal with them, and repeat forever

On the other hand, if I do something like
 repeat 30 [ if not stopflag [ go ] ]
and have a button that sets stopflag to true,  the button won't stop this endless go.
( try the code below )

Is there a way from code to press the GO-FOREVER button or cause whatever that button does to happen?

Something like
  repeat 30 [ if not stopflag [ go  handle-queued-button-presses ]]

;;================== code begins ======================
globals [stopflag ]
 
to setup
  clear-all
  set stopflag false;
  reset-ticks
end

to make-it-go
  set stopflag false
  repeat 30 [ if not stopflag [ go ] ]
end

to make-it-stop
  set stopflag true
end

to go  
  if stopflag [stop]
   print (word "running for ticks = " ticks)
   wait 0.25
   tick
end
;;============= code ends ========================
 




James Steiner

unread,
Jun 26, 2022, 8:26:56 PM6/26/22
to wade.s...@gmail.com, netlogo-users
There might be some trickery to be done using ask-concurrent or display or ticks or continuous updates. 

Theres also some trickery to be done with running reporters with "side-effects" in monitors. I did that with UI. A minimal UI is run in a monitor, until the user runs the "real" interactivity driver. 

But the rules have changed since netlogo 4 or 5 when it worked like I expected. I believe some experiments may reveal the best way to run code in a monitor that affects display that can be made to run at a predictable pace and also update the display. 

Note that the key to all of this is probably making sure to do something that affects the world to trigger something else to happen. 



--
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/34391cdb-062f-4b08-b808-76da2095e61en%40googlegroups.com.

James Steiner

unread,
Jun 26, 2022, 8:29:46 PM6/26/22
to wade.s...@gmail.com, netlogo-users
I'd say modify your stop test so that the world is touched every tick, even if just to rotate the hand of a clock, or flip-flop a single patch's color. The behavior may change. 

On Thu, Jun 23, 2022, 7:42 AM wade.s...@gmail.com <wade.s...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages