Netlogo: Ask expected this input to be a command block, but got a number instead - simulation

I'm getting this error "Ask expected this input to be a command block, but got a number instead" inside my setup procedure...
to setup
....
....
....
....
[ask color gray + 1.5]
Anyone have any ideas?

ask takes an agent or agentset as its first argument and a command block (something like [ ... ] that has commands in it) as its second. So, in your case, you probably want something like:
ask turtles [ set color gray + 1.5 ]

Related

On NetLogo, problem to use an ifelse statement inside a Monitor

On NetLogo, I am trying to create a Monitor that will show a string.
The code I am trying is:
(word "The current value is " (ifelse myvalue <= max_value [myvalue][max_value]) " in this model.")
myvalue and max_value are both global variables and integers.
Ideally, I would want the result to be something like:
The current value is 12 in this model.
But I always get the error Expected reporter and the ifelse statement highlighted, as if the problem were there.
I understand that one way to solve this would be to create another variable that would store the result of this ifelse elsewhere, and then just call here this new variable. However, if possible, I would prefer not to create a new variable, just to use the conditional inside the monitor itsel.
Does anyone knows why I am having this problem with Monitor?
ifelse is used to conditionally execute commands, ifelse-value is used to conditionally report values.
When you use word, NetLogo expects reporters but then finds ifelse, which NetLogo expects to store a command instead; therefore that error message and ifelse being highlighted.
This will work:
(word "The current value is " (ifelse-value myvalue <= max_value [myvalue][max_value]) " in this model.")

How does agent death surely affect the `while` loop that the agent is running?

As the following test illustrates, if a turtle is running a while when it dies, this breaks out of the while (without any error). Is this behavior guaranteed by NetLogo?
to test
ca
let age 0
crt 1
ask turtle 0 [
while [true] [
set age (1 + age)
print (word "age is " age)
if (random-float 1 < 0.1) [die] ;death ends the while
]
]
end
Yes- whenever a turtle executes "die" it immediately stops execution of any commands. In your case, the while loop (and "ask turtle 0") is terminated. The turtle is also automatically removed from all agentsets.
If you used "[die show "I'm dead!"]" instead of just "[die]", the code would never show "I'm dead!" because it stops as soon as it executes "die".
(If you have ever tried to program a model that removes agents in another programming language, you should appreciate how magical NetLogo's "die" primitive is. In other languages, doing the same thing can be a complicated nightmare.)

How can I clear the output portion of the Command Center.?

Is there a command to clear the output portion of the Command Center? I can't find one in the user-guide -- only commands to clear a separate output area if one was defined.
I'm using NetLogo 6.1.1. in Windows 10.
I don't have a separate output section defined. The command "clear-output" doesn't clear the output portion of the Command Center.
I tried making a separate output section on the interface, and print-output and clear-output work fine on it. But without a separate area, print-output goes to the command center but clear-output doesn't clear it.
Manually pushing the "clear" button on the interface does clear it.
Am I missing something obvious?
Manually entering these commands in the command center does not clear it:
print "x"
clear-output
Doing it from inside code doesn't seem to work either
to setup
clear-all
reset-ticks
end
to go
if (ticks > 4) [stop]
print ( word "line one at tick " ticks)
if (ticks > 3 ) [clear-output]
tick
end
The answer is "you can not". You can put an "Output" on the interface tab and use output-print instead of print. This way clear-output works perfectly.

Purpose of "stop" in NetLogo

I read a document about stop and some example code with stop in it. However, I'm still unsure about the usage of stop.
The following is how stop is used in the Ants Simple example in the model library. Could anyone help me understand the use of stop here?
to look-for-food ;; turtle procedure
;; turtle can access its own patch's property, in this line is `food`
ifelse food > 0 ;; if turtle's own patch has food on it
[ set carrying-food? true ;; pick up food --> change this turtle's carrying-food property to true
set food food - 1 ;; let's this patch losing one food
rt 180 ;; let turtle turn around
stop ;; no idea what is the use of stop here?????????????
]
[ ;; go in the direction where the pheromone smell is strongest
uphill-pheromone
]
stop can also be used to stop a BehaviorSpace model run. If the go commands directly call a procedure, then when that procedure calls stop, the run ends.
stop can also be used to stop a forever button.

Netlogo expected agentset error

I'm trying to create links between an "active-turtle" and a group of other turtles (which are currently stored in a list).
I want to make use of the create-links-with function, but am unable to without getting an error: expected input to be an agent-set but got a list...
This is my code ask active-turtle [create-links-with like-list]
I have a working solution, but I find it ugly so am looking for a better alternative
foreach like-list [ask ? [create-link-with active-turtle]]
The very handy turtle-set primitive will turn your list into an agentset!
ask active-turtle [ create-links-with turtle-set like-list ]