From Castle Wiki
Revision as of 07:21, 13 April 2023 by Ashh3b0oke (talk | contribs) (→‎Synchronizing events with the clock: I removed the use of two “use”.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Clock is a system for measuring time in Cards. It is useful for adding rhythmic events and logic to games, in particular when combined with the Music behavior, but it can be used by itself for anything where you need to measure time in a structured way.

Clock units

The clock measures time in bars, beats, and steps. Bars are the largest unit of time, several beats make up a bar, and several steps make up a beat. By default, there are four steps to a beat, and four beats to a bar.

The clock has a tempo measured in beats per minute. By default, the clock starts at 120 bpm.

Clock scope

There is one clock shared across the entire card. All of the Music across all of the Actors in the card will synchronize to the clock, and all time-related Rules in the card have the option of synchronizing to the clock.

When the player moves between cards in the same deck, the previous card's clock will finish its current bar before adopting the settings in the next card's clock. This means that if both cards share the same clock settings, any music which was already playing won't get interrupted by the navigation between cards.

Modifying the clock

From the editor, press the Gear icon at the top of the screen to open the Card Settings sheet. Then navigate to the Clock tab on that sheet. From here you can change the beats per bar, steps per beat, and tempo which will be used when the card starts.

While the card is playing, you can use the Set clock tempo response inside a Rule to change the tempo. You can read the current tempo using the Clock tempo Expression.

Synchronizing events with the clock

If your main goal is to play music, the best approach is to use the built-in Music behavior. If you want to do something more interactive, such as synchronize in-game events with the music, or with each other, you can use the clock.

Within Rules, any time-related Response can either use unstructured seconds (default) or can choose to use clock units. For example, the Wait response can Wait for 1 second, but it can also Wait for 1 beat or Wait until the next beat. Similarly, the Repeat response can either Repeat every 1 second, or it can Repeat every beat/bar/step.

The music-specific rule responses also contain options to synchronize with the clock. For example, you can do something like: Play this actor's song at the next bar.