How do I communicate (send/receive data, do calls..) via JS?

0 favourites
  • 7 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Here's the jist. We're creating a webpage, with a little bit of HTML & CSS (modals). We've made a back-end with API and the javascript from the page should load the data (via the API) locally. Now we modify and can work with the data (just on like any site).

    Now I want my data i just brought in to be able to be used by construct2 and vica versa, be able to do calls to Construct 2 from our JS, and the other way around (from our JS to Construct 2). All of this will be inside an IFrame.

    For example:

    The game starts, construct 2 game runs in the background (some cars are moving around) while the first html & css modal appears on top of the construct 2. This is going to be a small questionnaire modal (age, where you're from, gender, ...) and all will be handled outside of the game/construct (the game is still running automatically in the back ground).

    But then when the user completes his "registration" and clicks a button in html5/js ('Go to Game' or something), i have to trigger something in construct 2 so that the game goes from layout 1 to layout 2. I already know how to do this INSIDE construct 2, which is easy, but now i want it to work so that when a user presses a button in html5, a construct 2 function/event is called.

    Example 2:

    The game starts, does it's thing and after a certain period, say 5 seconds, another modal pops up with a question for the user. When he answers the question by clicking a button (in html5/js), the modal will disappear and something in construct 2 has to be triggered so that the car moves forward. When the car hits a certain point, another call has to go out from Construct 2 to our JS so that another modal may pop-up. etc...

    Does anyone know how to do this exactly?

  • rexrainbow hi there, this is just a test because i have no other way of contacting you (semi-)directly. I don't have 500 reputation yet therefor Scirra doesn't allow me to PM people (to counter spam users). If you receive a notification of this tag, could you please take a look at my issue when you can? On another post I made, you answered me your repo of several tens/hundreds of plugins. I'm unfortunately on a (sort of) tight schedule, so I can't spend hours digging in your most hughe and great collection of plugins.

    Maybe you could help me with my issue directly, or send me on my way referring to a plugin you previously made that's sort of the same?

    MUCH appreciated!

  • The best way: use the Javascript SDK

    Hacky quick fixes: the Browser object can execute Javascript, and you can call the Function object functions from JS.

  • The best way: scirra.com/manual/15/sdk use the Javascript SDK

    Hacky quick fixes: the scirra.com/manual/110/browser:tsk04xai]Browser object can execute Javascript, and you can call the [url=https://www.scirra.com/manual/149/function Function object functions from JS. Ah yes thank you, this is getting me partially where i'd have to be, but i'll get there . So say i wanted to call a function in a JS file somewhere, then I just use the execJS from browser? How does it know which file to look into? And then, when writing the own plugin, where do i put my functions so they can be used in construct 2? Like a function Next() in my JS file that checks if the data has been sent to a DB (like age, gender, etc...) and then that function calls a function object in Construct 2, that then initiates a set of actions?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You might see the source code of official websocket plugin first.

    To include external file, add

    "dependency": "file_name"

    in edittime.js, see SDK for more detail.

  • You might see the source code of scirra.com/manual/153/websocket official websocket plugin first.

    To include external file, add

    "dependency": "file_name"

    in edittime.js, see SDK for more detail.

    Ah great, thank you. I'll figure it out .

  • We created a plugin that can handle cross-domain post-messages.

    So, let's say when the user presses the button in the modal window you send a post-message and the plugin condition (Cnd) catches it and updates construct.

    Works both ways - when construct finishes something, it uses an actions, say AwesomePlugin.update, and it sends a post-message to the browser window.

    Works flawlessly.

    Hope this helps somehow.

    We also use this plugin to handle iframes/cross-domain.. etc.

    (I don't have 500 rep so search for "porthole js")

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