Struct tts_external_api::tcp::ExternalEditorApi
source · pub struct ExternalEditorApi { /* private fields */ }
Expand description
A struct representing Tabletop Simulators External Editor API.
Implementations§
source§impl ExternalEditorApi
impl ExternalEditorApi
sourcepub fn get_scripts(&self) -> Result<AnswerReload>
pub fn get_scripts(&self) -> Result<AnswerReload>
Get a list containing the states for every object. Returns an AnswerReload
message on success.
If no connection to the game can be established, an io::Error
gets returned instead.
sourcepub fn reload(&self, script_states: Value) -> Result<AnswerReload>
pub fn reload(&self, script_states: Value) -> Result<AnswerReload>
Update the Lua scripts and UI XML for any objects listed in the message,
and then reloads the save file, the same way it does when pressing “Save & Play” within the in-game editor.
Returns an AnswerReload
message.
If no connection to the game can be established, an io::Error
gets returned instead.
Any objects mentioned have both their Lua script and their UI XML updated. If no value is set for either the “script” or “ui” key then the corresponding Lua script or UI XML is deleted.
sourcepub fn custom_message(&self, message: Value) -> Result<()>
pub fn custom_message(&self, message: Value) -> Result<()>
Send a custom message to be forwarded to the onExternalMessage
event handler
in the currently loaded game. The value of customMessage must be an object,
and is passed as a parameter to the event handler.
If no connection to the game can be established, an io::Error
gets returned.
If this value is not an object then the event is not triggered.
sourcepub fn execute(&self, script: String) -> Result<AnswerReturn>
pub fn execute(&self, script: String) -> Result<AnswerReturn>
Executes a lua script globally and returns the value in a AnswerReturn
message.
If no connection to the game can be established, an io::Error
gets returned instead.
sourcepub fn execute_on_object(
&self,
script: String,
guid: String
) -> Result<AnswerReturn>
pub fn execute_on_object(
&self,
script: String,
guid: String
) -> Result<AnswerReturn>
Executes a lua script on an object and returns the value in a AnswerReturn
message.
If no connection to the game can be established, an io::Error
gets returned instead.
To execute Lua code for an object in the game that object must have an associated script in TTS. Otherwise the TTS scripting engine will fail with an error “function <executeScript>: Object reference not set to an instance of an object”. Once the in-game editor shows a script associated with an object then TTS will be able to execute Lua code sent via JSON message for that object.
source§impl ExternalEditorApi
impl ExternalEditorApi
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ExternalEditorApi struct and binds the TcpListener to its socket adress.