Skip to main content

Tick

Struct Tick 

Source
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

Source

pub const fn log(&mut self, log: bool)

Sets whether or not to log on tick advancement.

Examples found in repository?
examples/tutorial_new_game.rs (line 16)
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}
Source

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.

Source

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.

Source

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.

Source

pub fn advance_until<F>(&mut self, condition: F, max_ticks: u64) -> bool
where F: FnMut(&Tick) -> 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.

Source

pub const fn cur(&self) -> u64

Returns the current tick number.

Trait Implementations§

Source§

impl Debug for Tick

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Tick

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq<u64> for &Tick

Source§

fn eq(&self, other: &u64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd<u64> for &Tick

Source§

fn partial_cmp(&self, other: &u64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl Freeze for Tick

§

impl RefUnwindSafe for Tick

§

impl Send for Tick

§

impl Sync for Tick

§

impl Unpin for Tick

§

impl UnwindSafe for Tick

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.