Reputation: 89
I wrote the model that makes the daily life of the turtle and every the specific ticks that I assigned, the model will reset ticks
to 0 again and I have set in global
have day and every time my model reset, the number of days with + 1 in every loop. However, I want to make it like Monday, Tuesday, ..., Sunday and back again to Monday again.
Does anyone have any suggestions for the code?
Upvotes: 2
Views: 417
Reputation: 1473
If you don't need to know the actual date, because you are simply simulating time, you can use the "mod" function as JenB mentions above in a comment.
Here's an example that prints out a value of "day" that cycles each week. The example also has an offset in case you don't want to start on "Monday", and it shows how you could also get the name of the day ( such as "Monday") at the same time.
Enjoy!
;; IMPORTANT NOTE -- This doesn't look at the real world calendar,
;; You have to tell it what day is day zero.
;;
;; ticks start and zero and simply increment. You don't need to reset-ticks each week.
;; use the variable "day" for a value that starts at "offset" and increases by one each
;; day but also wraps back to zero automatically after it reaches 6
globals [
day ;; a numeric value from 0 to 6 representing day of the week
day-names ;; a list of names of the days you'd like to use
day-name ;; name of the current day based on the day-names list
offset ]
to setup
clear-all
set day-names ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
print day-names
set offset 0 ;; 0 starts the week on Sunday, offset 1 starts on Monday, etc.
reset-ticks
end
to go
if (ticks > 11 ) [stop] ;; don't consume the computer for this example
set day (offset + ticks) mod 7 ;; sets day from 0 to 6
set day-name item day day-names ;; picks up the name for that day if you want that
;; and let's print them out and confirm this is what we want
type "For offset " type offset
type ",Tick # " type ticks type " -> day # " type day type " which is " print day-name
tick
end
Upvotes: 1
Reputation: 1736
The Time extension is exactly for this. There is an old version here: https://github.com/colinsheppard/time (Click on "Clone or download", then "Download zip".) You can set one tick to equal one day, one week, etc., then label your results by date.
This extension is supposed to be in preparation to be packaged with future versions of NetLogo.
Upvotes: 0