How can I store each certain ticks in an arrangement in Netlogo

Viewed 15

I'm new in Netlogo and I need some help.

I am working on a small simulation and I need to store the values of a variable that constantly change in an array every 10 ticks.

I understand it is possible to use extensions [array], but I really don't understand how to solve my problem.

Thank you very much!

1 Answers

This short code snippet illustrates how you can add a value to a list every few ticks. The value changes every tick but is only added to the list every 10 ticks. I use ticks mod 10 to calculate the residue of dividing ticks by 10. This value is 0 every 10 ticks. To append an item to a list, you can use lput or fput.

globals [your-list]

to setup
  
  set your-list []
  reset-ticks
  
end

to go

  let your-item random-float 1
  if ticks mod 10 = 0 [set your-list lput your-item your-list]

  tick
  
end
Related