pub struct MemoryReference(_);
Expand description

A Reference to a screeps memory object

Implementations

Creates a MemoryReference from some JavaScript reference.

Warning: MemoryReference is only designed to work with “plain” JavaScript objects, and passing an array or a non-plain object into this method probably won’t be what you want. MemoryReference also gives access to all properties, so if this is indeed a plain object, all of its values should also be plain objects.

Passing a non-plain-object reference into this function won’t invoke undefined behavior in and of itself, but other functions can rely on MemoryReference being “plain”.

Get a dictionary value or create it if it does not exist.

If the value exists but is a different type, this will return None.

Gets a custom type. Will return None if null or undefined, and Err if incorrect type.

Example
use log::info;
use screeps::{prelude::*, Position};

let creep = screeps::game::creeps::get("mycreepname").unwrap();
let mem = creep.memory();
let pos = mem.get::<Position>("saved_pos").unwrap();
let pos = match pos {
    Some(pos) => {
        info!("found position: {}", pos);
        pos
    }
    None => {
        info!("no position. saving new one!");
        let pos = creep.pos();
        mem.set("saved_pos", pos);
        pos
    }
};
info!("final position: {}", pos);
creep.move_to(&pos);

Gets a custom type at a memory path. Will return None if null or undefined, and Err if incorrect type.

Uses lodash in JavaScript to evaluate the path. See https://lodash.com/docs/#get.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns the “default value” for a type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Casts this value as the target type, making the assumption that the types are correct. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.