H.Tan
H.Tan

Reputation: 59

How to set a minimum limit for a by-tick counter?

Ive created a patch-own variable which increases by "1" every time an agent lands on a particular patch.

It also decreases by 0.1 every tick.

So far the code looks like this

to go-predation-risk
  ask patch-here [
    set predation-risk predation-risk + 1]
end

to deduct-predation-risk
  ask patches [
    set pcolor scale-color green predation-risk 0 10
    set predation-risk predation-risk - 0.01
    if predation-risk <= 0 [
      set predation-risk 0]
  ]
end

Is there a way to set an upper and/or lower limit to the patch variable without specifying for example;

predation-risk <= 0 [
    set predation-risk 0]

I 'assume' that constantly calling this procedure to stop the variable going below 0 or above 10 will cause some performance issues when scaled up.

Cheers

Upvotes: 1

Views: 35

Answers (1)

JenB
JenB

Reputation: 17678

how scaled up do you want, as in how many patches? this is a fairly cheap operation and there aren't usually massive number of patches. Nevertheless, you could combine the decrease and test with if predation-risk >= 0.1 [set predation-risk predation-risk - 0.1]. Not sure it would be much quicker.

Just to let you know, if it is too slow when you do scale it up, you should look at the profiler extension to identify the slow points. Then you can focus on the important ones.

Upvotes: 1

Related Questions