[][src]Macro screeps::mem_get

macro_rules! mem_get {
    ($memory_reference:ident $($rest:tt)*) => { ... };
    (@so_far { $reference_so_far:expr } @rest [ $final_part_variable:expr ] . $accessor:ident) => { ... };
    (@so_far { $reference_so_far:expr } @rest . $final_part:ident . $accessor:ident) => { ... };
    (@so_far { $reference_so_far:expr } @rest [ $next_part_variable:expr ] $($rest:tt)+) => { ... };
    (@so_far { $reference_so_far:expr } @rest . $next_part:ident $($rest:tt)+) => { ... };
    ($($not_valid:tt)*) => { ... };
}

Get a value from memory given a path, returning None if any thing along the way does not exist.

Examples

Get a reference with type u32 at the path creeps.John.count.

#[macro_use]
extern crate screeps;

let mem = screeps::memory::root();
let val = mem_get!(mem.creeps.John.count.i32);

Get something using a variable path.

#[macro_use]
extern crate screeps;

let mem = screeps::memory::root();
let creep_name = "John";
let what_to_get = "count";
let val1 = mem_get!(mem.creeps[creep_name][what_to_get].i32);
let val2 = mem_get!(mem.creeps[creep_name].count.i32);
assert_eq!(val1, val2);

Accepted suffixes for type are methods that exist on MemoryReference, such as num, int, string, bool, arr and dict.