Giter Club home page Giter Club logo

coroutines's Introduction

Coroutines 1.4.0

Asynchronous execution in GML for GameMaker Studio 2.3.6 (and above)

Download the .yymps

Documentation

 

 

This library allows you to write pauseable functions in GameMaker. These pauseable functions are called "coroutines": a block of code that can be paused in the middle of execution and resumed later. Coroutines can be used for UI animation, complex networking protocols, REST API and OAuth flows, multi-stage visual effects, asynchronous save/load (required for console development), and more still. They're fantastically useful.

Getting coroutines to work in GameMaker is one thing, but making them fun to write requires a creative solution. Instead of implementing a slow custom scripting language or editor-side extension to generate coroutine-esque code, this library uses native GML macros to extend GML syntax to accommodate coroutine definitions. You can read all about the new syntax here or understand how and why it works here.

Because this library uses native GML at its core it is cross-platform, requires no additional software, and requires no external Included Files. The codebase is MIT Licensed and can be used everywhere, for free, forever. Regretably, GameMaker's HTML5 runtime is hot garbage and as a result this library is not supported for HTML5.

 

Please note that due to changes made in GMS2.3.6 to async event constant names, you will need to modify library code to get it to compile in versions older than v2.3.6.

coroutines's People

Contributors

jujuadams avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

coroutines's Issues

Typos in wiki?

For the CO_PARAMS section's sample code, shouldn't show_message(_message) be show_message(message) instead because we set CO_PARAMS.message = _message?

Add RESTART and PAUSE commands

At the moment calling .Restart(), .Pause(), or .Cancel() from within the target coroutine causes unexpected behaviour. Due to the way the coroutine VM works, coroutine execution state is only considered at the end of a code block (at a macro). This means exhibited behaviour is

CO_BEGIN
    show_debug_message("This appears");
    Restart();
    show_debug_message("And this does too");
CO_END

In order to work around this problem, two things need to be done:

  1. Prevent .Restart(), .Pause(), or .Cancel() being called from within the target coroutine (and should instead throw an error)
  2. Implement RESTART and PAUSE commands to create a breakpoint within the coroutine

Async event handling is broken on HTML5

case ev_async_web_networking: _key = "networking"; break;
case ev_async_web: _key = "http"; break;
case ev_async_social: _key = "social"; break;
case ev_async_save_load: _key = "save_load"; break;
case ev_async_dialog: _key = "dialog"; break;
case ev_async_web_steam: _key = "steam"; break;
case ev_async_system_event: _key = "system"; break;

Extracting the correct event name based on event_type and event_number doesn't work in HTML5 for reasons I haven't yet looked into.

Weird GameMaker error caused by lack of semicolon on preceeding line

show_debug_message("Broken")
CO_BEGIN ...

throws

Invalid callv target #2
 at gml_Object_obj_water_district_path_Step_0 (line 2) -        TRACE("Broken")
############################################################################################
gml_Object_obj_water_district_path_Step_0 (line 2)

fixed by

TRACE("Broken"); // <- added ;
CO_BEGIN ...

Add CO_LOCAL

Should point to the coroutine root struct currently being processed, or undefined otherwise. This will help with sandboxing variables when using CO_SCOPE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.