Rafaela
Rafaela

Reputation: 449

Different behavior of the turtles when viewing their labels in the interface using NetLogo 6.2. Why does this happen and how to solve it?

I have a doubt/intrigued by a NetLogo situation. Also, I don't know if there is a solution and the exact reason for this to occur.

I made a small code to exemplify my question...

What happens is the following:

  1. When I click on the setup button and then on the go and let for example 20 ticks pass, I have the following movement of the turtles (see figure below)

enter image description here

  1. But, if you press the setup button, then a button created in the interface to show and disapear the turtles labels (turtle labels) and then press go and leave the 20 ticks, another movement of the turtles appears (see figure below)

enter image description here

I would like to know why this happens? Will it be by the use of one-of?

And if there is any solution, because I need to see the turtle label in the interface to follow the model and check its operation.

If anyone has any ideas on how to resolve this and why this happens, I would appreciate it.

Thanks in advance :)

globals [ edge-size ValidHabs PatchSet  ] 
  
patches-own [ scale-patch ]

to setup
  ca
  random-seed 1 
  set ValidHabs [ [1] [2] [3] ] 
  set edge-size 60
  set-patch-size 20 
  let list1 ( list 4 8 )
  set PatchSet patches with [  
    ( pxcor mod ( 2 + 1 ) = 0 ) and ( pycor mod ( 2 + 1 ) = 0 ) ]
  (
    foreach ValidHabs [
      this-profile ->
      ask one-of PatchSet [ sprout 1 ]
  ]
  ) 
  ask patches [
    set scale-patch random 10
    set pcolor scale-color green scale-patch -8 12    
  ]
  reset-ticks 
end

to go 
  do-something 
  tick
end

to do-something 
  move-turtles  
end

to move-turtles
  ask turtles [
    rt random-normal 0 90      
    fd 3
    set color black
    pen-down
    set pen-size 2
  ]
end


;Interface button code (turtle labels)
;ask turtles [
;  ifelse label = "" [    
;    set label  ( who )
;    set label-color white
;  ] 
;  [    
;    set label ""
;  ]
;]

Upvotes: 1

Views: 45

Answers (1)

Luke C
Luke C

Reputation: 10291

Great job with the minimum reproducible example, that's really helpful! If I understand what you're asking, you're wondering why, despite setting random-seed, there is a difference between your two runs? If that's the case, I think it's because you are doing an extra action (ask turtles [...) that relies on randomness to operate. When you ask turtles, the turtles act in a random order. So, if you need the turtles to move the same way each time, one quick way around that is to set the random number right before the action you're trying to replicate. For example, if I change your move-turtles to:

to move-turtles
  random-seed 123
  ask turtles [
    rt random-normal 0 90      
    fd 3
    set color black
    pen-down
    set pen-size 2
  ]
end

And then run go 4 times, I get this movement pattern without labels: enter image description here

And the same one if I setup -> label -> go x 4: enter image description here

Hopefully that gets you pointed in the right direction!

Upvotes: 2

Related Questions