I am trying to make a Frogger-like game in NetLogo and I need to create a timer that counts down. However, I looked in Frogger and used the same procedures that create the timer but it does not work. Please advise.
相关问题
- Timer vs. repetitive background worker
- Making turtles wait x number of ticks
- setInterval doesn't slow down on inactive tab
- Timers not running when screen is turned off / dev
- How to set timer in an event handler?
相关文章
- Is the HPET directly accessible in Windows?
- Blinking Button for Simon Says
- Timer Label not updated after switching views (swi
- Indy TIdTCPClient receive text
- A HR timers precision study case
- Chrono Timer Not Converting Seconds Properly
- How to move several buttons throughout the screen
- Precise loop timing in Python
How to create a count-down timer in NetLogo
This is a general outline of how to implement a count-down timer. This applies both to a real-time count-down, or a simulation-time count-down.
Implement a variable to contain the remaining time or elapsed time.
The variable is usually a global variable, unless each agent must have its own count-down. Then the variable will be a -own'd variable of the agent.
I think it's generally best to track time-remaining. The count-down variable is initialized with the duration of the count-down. This makes it easy (in a game) to implement bonuses that extend the count-down, and penalties that reduce it, by simply adding to or subrtacting from the time remaining. Tracking the "actual" time that the count-down expires (using
timer + duration
or something similar) is generally less useful, especially if your game can be paused. Undesired effects could occur that you would have to code around.Implement a procedure to initialize the count-down.
Implement a procedure to decrement the remaining time.
Implement a procedure to test whether the count-down has expired.
Implement a way to display the time remaining or elapsed time. For example:
Use a patch label to show the time:
use a specially defined turtle with a clock shape to show the time elapsing. Examples of this exist in the NetLogo Models Library
Implement the action that occurs when the timer expires.
This is entirely up to you.
This may involve resetting the timer for another count-down.
To use the count-down timer in your program you must:
Initialise the count-down timer where appropriate (such as when the game, or a round of the game, begins).
Change and test the timer.
This might be once per "tick", or a calulation based on real time.
Act on the expired timer.
Recurring Events
If what you need is a way to trigger recurring events every N ticks, you may be able to simply use the
mod
operator with theticks
counter in yourgo
procedeure:The above code line would cause the procedure
perform-recurring-event
to run every time theticks
counter reached 0 or a multiple of 30. In other words, it would run every 30ticks
.