SkillAgentSearch skills...

Promise.gml

An adaptation of JavaScript Promise polyfill for GameMaker Studio 2.3+

Install / Use

/learn @YAL-GameMaker/Promise.gml
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Promise.gml

An adaptation of JavaScript Promises for GameMaker Studio 2.3+, based on this polyfill.

JS➜GML Equivalents

GameMaker does not allow using built-in function names as variable names, so:

Changes

GameMaker does not allow naming methods same as keywords, therefore:

  • thenandThen
  • catchandCatch
  • finallyandFinally
  • allafterAll

Examples

Can also be found in the sample project, along with supporting scripts.

Basic (ft. custom setTimeout):

(new Promise(function(done, fail) {
	setTimeout(function(_done, _fail) {
		if (random(2) >= 1) _done("hello!"); else _fail("bye!");
	}, 250, done, fail);
})).andThen(function(_val) {
	trace("resolved!", _val);
}, function(_val) {
	trace("failed!", _val);
})

afterAll:

Promise.afterAll([
	Promise.resolve(3),
	42,
	new Promise(function(resolve, reject) {
		setTimeout(resolve, 100, "foo");
	})
]).andThen(function(values) {
	trace(values);
});

Chaining HTTP requests (ft. custom HTTP wrappers):

http_get_promise("https://yal.cc/ping").andThen(function(v) {
	trace("success", v);
	return http_get_promise("https://yal.cc/ping");
}).andThen(function(v) {
	trace("success2", v);
}).andCatch(function(e) {
	trace("failed", e);
})

Caveats

  • Non-exact naming (but feel free to pick your own aliases).
  • Have to "promisify" built-in functions to be able to finely use them with promises.
  • I could not port the original JS library's unit tests because their dependencies have far more code than the library itself.
View on GitHub
GitHub Stars25
CategoryDevelopment
Updated3mo ago
Forks1

Languages

Game Maker Language

Security Score

72/100

Audited on Dec 3, 2025

No findings