Skip to content

Crate to trigger GMS2 async events from Rust.

Notifications You must be signed in to change notification settings

FssAy/async_load

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Load

This crate contains functionality to trigger GMS2 async events and pass data into them by using a ds_map structure inside a global async_load variable.

About

GMS2 (Game Maker Studio 2) is an engine for building games on all kind of platforms that uses GML (Game Maker Language).

It's possible to enhance its functionality with extensions (custom libraries).
This crate helps with building one that can "call GML from Rust".

How To Use

In order to be able to perform any kind of operation, it's necessary to define an external RegisterCallbacks function.
It can be found in src/lib.rs.

To activate it simply enable the extension feature:

[dependencies.ds_map]
version = "1.0.2"
features = [
    "extension",
]

(You can also keep the feature disabled and define RegisterCallbacks manually)

Then while inside of your GMS2 project, open your extension and add a new function as seen on the image bellow:

Do not call this function, it will be executed automatically by the GMS2.

This will register all the necessary callbacks and allow you to use the DSMap structure.

Example

Rust:

#[no_mangle]
#[allow(non_snake_case, unused_variables)]
pub unsafe extern "C" fn MyFunction() -> GMLDouble {
    use std::thread::*;
    use std::time::Duration;

    // Spawn new thread.
    spawn(|| {
        // Wait for 1 second.
        sleep(Duration::from_secs(1));

        // Create and dispatch the map.
        let mut map = DSMap::new();
        map.add_double("key1", 21.37);
        map.add_string("key2", "Hello from Rust!");
        map.dispatch(EventType::Social);
    });

    GMLDouble::none()
}

GMS2 object Create event:

show_debug_message("[*] Start");
MyFunction();
show_debug_message("[*] Finished");

GMS2 object Async - Social event:

show_debug_message("[*] Async - Social");
show_debug_message(async_load[? "key1"]);
show_debug_message(async_load[? "key2"]);

Output:

[*] Start
[*] Finished

(...) <some other info>

[*] Async - Social
21.37
Hello from Rust!

About

Crate to trigger GMS2 async events from Rust.

Resources

Stars

Watchers

Forks

Languages