run runresult

run command-task (run command-task input1 ...) run string runresult reporter-task (runresult reporter-task input1 ...) runresult string

The run form expects a command task or a string containing commands. This agent then runs them.

The runresult form expects a reporter task or a string containing a reporter. This agent runs it and reports the result.

Note that you can't use run to define or redefine procedures. If you care about performance, note that the code must be compiled first which takes time. However, compiled bits of code are cached by NetLogo and thus using run on the same string over and over is much faster than running different strings. The first run, though, will be many times slower than running the same code directly, or in a command task.

Tasks are recommended over strings whenever possible. (An example of when you must use strings is if you accept pieces of code from the user of your model.)

Tasks may freely read and/or set local variables and procedure inputs. Trying to do the same with strings may or may not work and should not be relied on.

When using tasks, you can provide them with inputs, if you surround the entire call with parentheses. For example:

(run task [ crt ?1 [ fd ?2 ] ] 10 5)
;; creates 10 turtles and move them forward 5 steps
show (runresult task [ ?1 + ?2 ] 10 5)
=> 15
;; adds 10 and 5

Take me to the full NetLogo Dictionary