Referencing Construct objects/variables in JS?

  • Been trying to fiddle with the new Javascript support in C3 but can't seem to understand how to reference Construct objects such as Browser, Geolocation, Keyboard etc.

    Anyone have any success getting those referenced in the JS? The "const" thingy used in the announcement blog posts just gives an error whenever I try to preview the game.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure if you've found it yet but the scripting documentation tells you how to do this.

    You can get a reference to the object class with

    const Sprite = runtime.objects.Sprite; // Sprite object class
    const first = Sprite.getFirstInstance(); // first instance of Sprite
    const instances = Sprite.getAllInstances(); // all instances of Sprite
    

    Not all types have full interfaces yet, the ones that so are listed under the "Plugin interfaces" section in the documentation menu. However, there are a set of common methods for object classes and instances that exist for doing things like creating new instances, destroying old ones and moving them around the layout.

  • Thank you so much for the reply!

    The documentation was just what I needed. Couldn't find it by myself. Global variables work already, which is nice :)

  • Glad to hear. Have fun and let us know if you have any feedback. Bear in mind that both the feature and documentation are still beta at the moment.

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