pub trait ScriptVariableRead: PartialEq + Eq {
Show 13 methods // Required method fn id(&self) -> ScriptVariableId; // Provided methods fn descriptor(&self) -> &script_var { ... } fn is_local(&self) -> bool { ... } fn var_type(&self) -> ScriptVariableValueType { ... } fn is_array(&self) -> bool { ... } fn capacity(&self) -> usize { ... } fn name(&self) -> &str { ... } fn value_raw(&self) -> i32 { ... } fn value_raw_indexed(&self, index: i32) -> i32 { ... } fn value(&self) -> ScriptVariableValue { ... } fn value_indexed(&self, index: i32) -> ScriptVariableValue { ... } fn sum(&self) -> i32 { ... } fn var_eq<S: AsScriptVariableId>(&self, other: S) -> bool { ... }
}
Expand description

Read actions for script variables.

Required Methods§

source

fn id(&self) -> ScriptVariableId

Returns the variable ID

Provided Methods§

source

fn descriptor(&self) -> &script_var

Loads a script variable descriptor for a given ID.

source

fn is_local(&self) -> bool

Returns whether or not this is a local variable (as opposed to a global one).

source

fn var_type(&self) -> ScriptVariableValueType

Returns the type of the variable

source

fn is_array(&self) -> bool

Returns whether or not the variable is an array.

source

fn capacity(&self) -> usize

Returns the number of elements in the array or 1 if it’s not an array.

source

fn name(&self) -> &str

Returns the name of the variable.

source

fn value_raw(&self) -> i32

Loads the value of a script variable. If this variable is an array, the value at index 0 is returned.

This will return the value of the variable as a i32, no matter the type of the variable.

source

fn value_raw_indexed(&self, index: i32) -> i32

Loads the value of a script variable at some index (for script variables that are arrays).

This will return the value of the variable as a i32, no matter the type of the variable.

source

fn value(&self) -> ScriptVariableValue

Loads the value of a script variable.

If this variable is an array, the value at index 0 is returned. Special case: If the type is a string, the entire string is returned.

This will return the value of the variable as an enum variant of ScriptVariableValue, the variant will depend on the type of this variable. You can get the type with Self::var_type and force a cast with that:

use eos_rs::api::script_vars::{ScriptVariableRead, UnwrapScriptVariableValueAs};

fn demo(script_var: impl ScriptVariableRead) {
    // Assuming that `script_var` is a boolean variable. If it isn't, this will panic.
    let value: bool = script_var.value().unwrap_as(script_var.var_type());
}
source

fn value_indexed(&self, index: i32) -> ScriptVariableValue

Loads the value of a script variable at some index (for script variables that are arrays).

Panics if the read is out of bounds.

Special case: If the type is a string, the character at the given position is returned (but still as a valid single-character CString).

This will return the value of the variable as an enum variant of ScriptVariableValue, see Self::value for more information.

source

fn sum(&self) -> i32

Loads the sum of all values of the script variable (for script variables that are arrays).

source

fn var_eq<S: AsScriptVariableId>(&self, other: S) -> bool

Checks if two script variables have equal values. For arrays, compares elementwise for the length of the first variable.

Hint: Implementors of this trait also implement PartialEq and Eq, so you can use those instead if the underlying type is the same.

Implementors§