How do I have an iframe / embedded C3 game communicate with an external program like Twine?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
[C2] [C3] Support C3 build service and Android 14
  • I know that Construct 3 has a sandbox environment. But is there a way for an embedded iframe to communicate a variable to a program like Twine / Pubcoder? I would love to subscribe to and use Construct, but I've not found anything that works and it's a necessity for me? Thank you for any and all help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Messaging between frames on the same page can be done with the postMessage() JavaScript API. Some services also provide a JavaScript API you can use.

    If neither is applicable and you want to communicate with an entirely separate application which does not provide any JavaScript API, it is tricky. Your best options are probably a WebSocket or a browser extension - but you'll still need to know how the external application works and how to message it.

  • Thank you for your reply! Sorry, but I'm slightly struggling with the postMessage(). I'm trying to apply it to Action > Browser > Execute Javascript but it says that 'window' isn't recognised as an object. Am I going about this the correct way, and if so, what is the correct line of code which won't be restricted by Construct?

    I've tried some variations based around window.parent.postMessage("message", "*");

  • Don't use 'Execute Javascript', you can just insert a script action directly in the event sheet which is much easier to work with.

    You probably need to turn off 'Use worker' in project properties, as by default the runtime runs in a web worker without direct access to DOM properties like 'window' and 'document'. The manual guide on JavaScript in Construct explains that more. And if you use a script action in the event sheet, Construct defaults worker mode to off so all those APIs will just work like you expect.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)