samedi 3 septembre 2016

Trouble with parenthesis placement and the ifelse and let commands in Netlogo.

I am having trouble with parenthesis placement and the ifelse and let commands in Netlogo.

I have a variety of different conditions relating to patches-own (envi) and turtles-own (niche-opt, niche-range) variables that determine a local-variable (multi), that will then be used to determine the probability of reproduction.

Turtles have a variable niche-opt, if this matches the patch variable envi then the local variable multi = 1

If niche-opt != envi but envi is within niche-opt +- niche-range (turtle variable, integer ranging from 1 - 3) then multi = 0.8

And finally if envi is outside niche-opt +- niche-range then multi = 0.2

So the local variable "multi" can be one of three values (1,0.8 or 0.2), which is then multiplied with a turtles-own variable (trait-2) and used to determine the probability of hatch occurring.

My issue is that in the line of code:

if random-float 100 < (multi * trait-2 * 100)

comes up with the error "nothing named multi defined". I am sure the issue is to do with my bracket placements as let creates a local variable, but I cannot figure out if I need to add more brackets or just move the ones I have.

to go
   ask turtles [
   reproduce  
   ]
end

to reproduce  
  ifelse niche-opt = envi  
  [let multi 1] 
  [ifelse envi >= (niche-opt - niche-range) or envi <= (niche-opt + niche-range)
  [let multi 0.8]
  [let multi 0.2]
  ]
if random-float 100 < (multi * trait-2 * 100)
hatch 1 
end

Aucun commentaire:

Enregistrer un commentaire