Search code examples
netlogo

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?


Solution

  • 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.")