pub struct Tick { /* private fields */ }Expand description
The tick is used to keep track of time in the game.
You can advance the game using the advance method or similar.
Many functions and building methods require a Tick to be passed in, which allows them to update their state.
If a function takes a &mut Tick, then the function will take time.
If a function merely takes a &Tick, it will never advance the game time, but instead just roll forward it’s internal state to match the current tick.
§Examples
Let’s say we have two furnaces the we want to fill with iron_ore and copper_ore respectively, and then advance time so they can smelt the ore into ingots:
// Add ore to the furnaces at the current tick
furnace1.inputs(&tick).0.add(iron_ore);
furnace2.inputs(&tick).0.add(copper_ore);
// Advance time by 10 ticks so the furnaces can process some of the ore.
tick.advance_by(10);
// Now we can extract the smelted ingots from the furnaces
let iron_ingots = furnace1.outputs(&tick).0.empty().unwrap();
let copper_ingots = furnace2.outputs(&tick).0.empty().unwrap();Implementations§
Source§impl Tick
impl Tick
Sourcepub const fn log(&mut self, log: bool)
pub const fn log(&mut self, log: bool)
Sets whether or not to log on tick advancement.
Examples found in repository?
15fn user_main(mut tick: Tick, starting_resources: StartingResources) -> (Tick, Bundle<Copper, 4>) {
16 tick.log(true);
17
18 let StartingResources {
19 iron,
20 mut iron_territory,
21 mut copper_territory,
22 guide,
23 } = starting_resources;
24
25 // To start, run the game using `rustorio play tutorial` (or whatever this save is called), and follow the hint.
26 // If you get stuck, try giving the guide other objects you've found, like the `tick` object.
27 guide.hint(iron)
28}Sourcepub fn advance(&mut self)
pub fn advance(&mut self)
Advances the game by one tick.
By default prints the current tick number to the console.
If you want to disable this, use the log method.
Sourcepub fn advance_by(&mut self, ticks: u64)
pub fn advance_by(&mut self, ticks: u64)
Advances the game by the specified number of ticks.
By default prints the current tick number to the console.
If you want to disable this, use the log method.
Sourcepub fn advance_to_tick(&mut self, target_tick: u64)
pub fn advance_to_tick(&mut self, target_tick: u64)
Advances the game until the specified tick number is reached. Does nothing if the target tick is less than or equal to the current tick.
By default prints the current tick number to the console.
If you want to disable this, use the log method.
Sourcepub fn advance_until<F>(&mut self, condition: F, max_ticks: u64) -> bool
pub fn advance_until<F>(&mut self, condition: F, max_ticks: u64) -> bool
Advances the game until the specified condition is met or the maximum number of ticks has passed.
Returns true if the condition was met, or false if the maximum number of ticks was reached first.
By default prints the current tick number to the console every tick.
If you want to disable this, use the log method.