Transactions, Promises & You

Have you ever been rate limited trying to set lots of objects in your space? (if not, the rate limit is 45 actions every 2 seconds, or ~22 actions per second) Have you ever accumulated a lot of lag doing a bunch of actions and realized you need to wait for one action to complete before doing the next? We support transactions in most actions you can take on the gameserver. Transactions allow you to wrap your action in a Promise so you can use the await keyword. Here’s how to do it:

The most common place this is useful is in setting objects, which takes an optional third useTxnId parameter. Set it to true and setObject can be awaited. In any async function:

  await setObject("foo", { myCoolObject }, true);

Or, just for a quick refresher for those unfamiliar, you can also staple a then onto the end, which will be called when setObject is done

   setObject("foo", { myCoolObject }, true).then(() => console.log("I'm done setting the object!"));

For most other actions, you can manually call game.engine.sendAction and pass in two more variables, bypass and createTxnId. bypass bumps the event to the front of the event queue, and should almost always be set to false. Set createTxnId to true and you can await sendAction.

If there are other actions you send a lot, and you want us to add an optional parameter like setObject has to make it easier for you, please let us know!

Tagging @Kevin-RtR since I know this is a question you’ve asked before, and I realized this is the real answer!

Happy hacking & happy holidays,



Works like a charm! Thanks so much Evelyn!