pub struct LuaHelpers;Expand description
Provides various helper and utility functions. It is accessible through the global object named helpers in all stages (settings, prototype and runtime).
Implementations§
Source§impl LuaHelpers
impl LuaHelpers
Sourcepub fn game_version(&self) -> &str
pub fn game_version(&self) -> &str
Current version of game
Sourcepub fn instrument_mod(&self) -> &str
pub fn instrument_mod(&self) -> &str
The name of the active Instrument Mode mod, if any.
Sourcepub fn object_name(&self) -> &str
pub fn object_name(&self) -> &str
The class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
Sourcepub fn stage(&self) -> LuaHelpersStage
pub fn stage(&self) -> LuaHelpersStage
Stage of scripting that is currently running
Sourcepub fn check_prototype_translations(&self)
pub fn check_prototype_translations(&self)
Goes over all items, entities, tiles, recipes, technologies among other things and logs if the locale is incorrect.
Also prints true/false if called from the console.
Not available in settings and prototype stages.
Sourcepub fn compare_versions(&self, first: &str, second: &str) -> i32
pub fn compare_versions(&self, first: &str, second: &str) -> i32
Compares 2 version strings.
Sourcepub fn create_profiler(&self, stopped: Option<bool>) -> LuaProfiler
pub fn create_profiler(&self, stopped: Option<bool>) -> LuaProfiler
Creates a LuaProfiler, which is used for measuring script performance.
LuaProfiler cannot be serialized.
Not available in settings and prototype stages.
Sourcepub fn decode_string(&self, string: &str) -> Option<&str>
pub fn decode_string(&self, string: &str) -> Option<&str>
Base64 decodes and inflates the given string.
Sourcepub fn direction_to_string(&self, direction: &str) -> &str
pub fn direction_to_string(&self, direction: &str) -> &str
Converts the given direction into the string version of the direction.
Sourcepub fn encode_string(&self, string: &str) -> Option<&str>
pub fn encode_string(&self, string: &str) -> Option<&str>
Deflates and base64 encodes the given string.
Sourcepub fn evaluate_expression(
&self,
expression: MathExpression,
variables: Option<HashMap<String, f64>>,
) -> f64
pub fn evaluate_expression( &self, expression: MathExpression, variables: Option<HashMap<String, f64>>, ) -> f64
Evaluate an expression, substituting variables as provided.
Sourcepub fn is_valid_ambient_sound(&self, name: &str) -> bool
pub fn is_valid_ambient_sound(&self, name: &str) -> bool
Checks if an ambient sound of a given name is valid.
Not available in settings and prototype stages.
Sourcepub fn is_valid_animation_path(&self, name: &str) -> bool
pub fn is_valid_animation_path(&self, name: &str) -> bool
Checks if the given animation name is valid and contains a loaded animation.
Not available in settings and prototype stages.
Sourcepub fn is_valid_sound_path(&self, sound_path: SoundPath) -> bool
pub fn is_valid_sound_path(&self, sound_path: SoundPath) -> bool
Checks if the given SoundPath is valid.
Not available in settings and prototype stages.
Sourcepub fn is_valid_sprite_path(&self, sprite_path: SpritePath) -> bool
pub fn is_valid_sprite_path(&self, sprite_path: SpritePath) -> bool
Checks if the given SpritePath is valid and contains a loaded sprite. The existence of the image is not checked for paths of type file.
Not available in settings and prototype stages.
Sourcepub fn json_to_table(&self, json: &str) -> Option<LuaAny>
pub fn json_to_table(&self, json: &str) -> Option<LuaAny>
Convert a JSON string to a table.
Sourcepub fn multilingual_to_lower(&self, input: &str) -> &str
pub fn multilingual_to_lower(&self, input: &str) -> &str
Converts the given string to lowercase and returns it. Unlike string.lower(), this function supports non-Latin characters.
Sourcepub fn parse_map_exchange_string(
&self,
map_exchange_string: &str,
) -> MapExchangeStringData
pub fn parse_map_exchange_string( &self, map_exchange_string: &str, ) -> MapExchangeStringData
Convert a map exchange string to map gen settings and map settings.
Not available in settings and prototype stages.
Sourcepub fn recv_udp(&self, for_player: Option<u32>)
pub fn recv_udp(&self, for_player: Option<u32>)
Dispatch defines.events.on_udp_packet_received events for any new packets received by the specified player or the server.
This must be enabled per-instance with --enable-lua-udp.
UDP socket when enabled requests 256KB of receive buffer from the operating system. If there is more data than this between two subsequent calls of this method, data will be lost. That also applies to periods when the game is paused or is being saved as in those case the game update is not happening.
Note: lua event is not raised immediately as the UDP packet needs to be introduced into game state by means of input actions. Please keep incoming traffic as small as possible as in case of multiplayer game with many players, all this data will have to go through the multiplayer server and be distributed to all clients.
Not available in settings and prototype stages.
Sourcepub fn remove_path(&self, path: &str)
pub fn remove_path(&self, path: &str)
Remove a file or directory in the script-output folder, located in the game’s user data directory. Can be used to remove files created by LuaHelpers::write_file.
Sourcepub fn send_udp(&self, data: &str, for_player: Option<u32>, port: u16)
pub fn send_udp(&self, data: &str, for_player: Option<u32>, port: u16)
Send data to a UDP port on localhost for a specified player, if enabled.
This must be enabled per-instance with --enable-lua-udp.
Sourcepub fn table_to_json(&self, data: LuaAny) -> &str
pub fn table_to_json(&self, data: LuaAny) -> &str
Convert a table to a JSON string
Sourcepub fn write_file(
&self,
append: Option<bool>,
data: &str,
filename: &str,
for_player: Option<u32>,
)
pub fn write_file( &self, append: Option<bool>, data: &str, filename: &str, for_player: Option<u32>, )
Write a file to the script-output folder, located in the game’s user data directory. The name and file extension of the file can be specified via the filename parameter.
Trait Implementations§
Source§impl Clone for LuaHelpers
impl Clone for LuaHelpers
Source§fn clone(&self) -> LuaHelpers
fn clone(&self) -> LuaHelpers
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more