I'm trying to get turtles in Netlogo to "stay put" for 20 clicks, before moving on (just going forward), but I keep getting "expected command" errors. Any idea where my bracketing is incorrect?
Thanks!
to solar-battery ;; trying to ask turtles to move forward after being stationary for 20
clicks
ask turtles [
[ifelse (patch-here = destination)
[
if (ticks - ticks-since-here > ticks-to-stay-on-patch patch-here)
[
set ticks-since-here 20
set destination one-of patch]]]
[face destination
forward 1
if [patch-here = destination]
[set ticks-since-here ticks]]]
end
Since comments don't allow newlines and indenting... here's a sample of code formatting.
to do-stuff
ask turtles with [ pxcor > 0 ] ;; this is fine.
[ ;; open of code block
jump 1
if (pcolor = white)
[ ;; open code block
rt 90 jump 1
] ;; close block
] ;; close block
end
One place where other arrangements of brackets HELP rather than confuse is when simulating a SWITCH structure:
When doing a switch, keep the conditions and actions VERY SHORT. If they are long, wrap the conditions in a reporter. Likewise, wrap the action in a procedure, unless it is VERY SHORT.
if-else (condition1) [ action 1 ][
if-else (condition2) [ action 2 ][
if-else (condition3) [ action 3 ][
if-else (condition4) [ action 4 ][
;; OTHERWISE
default-action
]]]] ;; one close bracket for each condition.
This format makes it VERY easy to add, remove, or re-order conditions, without having to mess with moving brackets, changing indents, or mismatching brackets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.