Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetLogo: Can't "stop" forever button from another procedure?

I have simplified my problem below. I want to stop the execution of the forever button "go" when there's no robots, and I want to call this from another procedure ("test" in this case) like so:

to go
 test
end

to test
  if not any? robots [ stop ]
end

The reason for this is that I want to call stop where the robot dies such that I can send an appropriate user message.

like image 529
SJ19 Avatar asked Oct 23 '25 01:10

SJ19


1 Answers

Sadly, you must re-organize your code so that the you call if not any? robots [ stop ] in your go in order for the following to be true:

See the documentation:

A forever button can also be stopped from code. If the forever button directly calls a procedure, then when that procedure stops, the button stops. (In a turtle or patch forever button, the button won’t stop until every turtle or patch stops – a single turtle or patch doesn’t have the power to stop the whole button.)

Ref:http://ccl.northwestern.edu/netlogo/docs/programming.html#buttons

stop This agent exits immediately from the enclosing procedure, ask, or ask-like construct (e.g. crt, hatch, sprout). Only the enclosing procedure or construct stops, not all execution for the agent.

Ref: http://ccl.northwestern.edu/netlogo/docs/dict/stop.html

One alternative hacky solution which I'm tempted to not post may be to do the following where you raise an error in which then stops.

to go
   carefully[test][error-message stop]
end
to test
   if not any? robots [ error "no more robots!" ]
end
like image 73
mattsap Avatar answered Oct 25 '25 06:10

mattsap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!