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 ========================