A proposal for Javascript scripting in Construct 3

You're viewing a single comment in a conversation. View all the comments
  • 22 Comments

  • Order by
    • [-] [+]
    • 2
    • Ashley's avatar
    • Ashley
    • Construct Team Founder
    • 2 points
    • (21 children)

    It's a way of using your own custom class deriving from WorldInstance. So you can add all your own custom properties and functions, and still do everything WorldInstance does.

      • [-] [+]
      • 2
      • skymen's avatar
      • skymen
      • Affiliate
      • 2 points
      • *
      • (20 children)

      That's interesting, how would it work exactly?

      Is it already possible in r151?

      Edit: nvm I just got what you meant. But that's already what I kinda do in the article, except I don't have access to the WorldInstance class so I made my own and get WorldInstance later. I didn't mean to make it possible, I meant to make it integrated in the editor and have a better workflow for it

        • [-] [+]
        • 1
        • Ashley's avatar
        • Ashley
        • Construct Team Founder
        • 1 points
        • (19 children)

        See Subclassing instances for how this works in r152.

        • That is pretty cool indeed, that's enough to write some kind of workflow of my own. However I still think it would be pretty cool to see an integrated workflow to the editor in order to make development easier when using JS only.

            • [-] [+]
            • 1
            • Ashley's avatar
            • Ashley
            • Construct Team Founder
            • 1 points
            • (17 children)

            I don't know what you mean by that - can you explain exactly what that would do, how it would work, and what benefits it would offer the way it works with subclassing?

            • Well the simple answer is:

              Right now it's technically possible to make games using JS only. However the things you did for Ghost Shooter will not work for a much bigger project. Anything that will have more than 10 concurrent systems working together will be very hard to organise to work with.

              I would love to actually write something that would represent what I mean, but I'd need to properly design (and possibly code) it for it to be crystal clear. And even then, since I have only a limited understanding of the inner workings of the engine and that I cant access the engine code, you will very probably find flaws to what I can give you.

                • [-] [+]
                • 1
                • Ashley's avatar
                • Ashley
                • Construct Team Founder
                • 1 points
                • (11 children)

                I don't see why the approach used in the Ghost Shooter code demo wouldn't work for a large project. You can sub-class as many kinds of object as you like.

                You can also use a deeper class heirarchy to avoid code duplication. This is just normal use of JavaScript classes. For example you could have custom MonsterEnemyInstance and ZombieEnemyInstance classes, both of which derive from a custom EnemyInstance class, which derives from Construct's IWorldInstance. Now you can do things like write a single EnemyInstance.die() method, and it can be used with both MonsterEnemyInstance and ZombieEnemyInstance. So as far as I can tell this appears suitably scalable to large projects without code duplication.

                • Well here are two issues I can kinda think of at the moment:

                  1- What if you want to instantiate two ghosts but with different data. Different speeds, or different sizes etc all of that being defined from the layout.

                  2- What if you want to write something that can apply to more than just a Sprite, like a CameraObject script where every instance that has this class associated to it can control the camera a bit, by offsetting it or by fully taking control.

                  There are things that cant entirely be done only using subclassing just like things can't all be done by paralelizing features (like how families are used with one "solid" family, one "health" family etc).

                  The way Unity does it allows to have the best of both worlds. That's kind of what I mean.

                  Load more comments (7 replies)
                  • [-] [+]
                  • 1
                  • Ashley's avatar
                  • Ashley
                  • Construct Team Founder
                  • 1 points
                  • (2 children)

                  Also I haven't used GameMaker or Unity much, but I don't think it's too helpful to refer to them - either the language is significantly different to JavaScript, or the way the editor works is significantly different to Construct, or maybe even they have poorly designed features which they're stuck with for backwards-compatibility reasons, and it wouldn't be sensible to copy that. So I think it's worth designing (and explaining) everything from scratch, although that can be informed by how it works in other tools.

                  Load more comments (2 replies)
              • Anyway, the idea is to have a unified way to write js scripts that can better fit larger projects, which are the ones that will probably make most use out of the js feature.

                That's the main benefit: Being able to easily write JS code that can be extended and modified at ease without having to preface it with tons of utility functions and an additionnal layer.

                How it would work: Sadly I cant really go into more details than what I say in the blog post. I will try to write something using the available features and send a c3p file once I have something that's closer to what I envisionned using the newly available features but it's still gonna be limited compared to what you guys could actually do.

                • Anyway, if all of that doesn't really make sense to you, then I'm really sorry, I will try my best to make it clearer once I write some code. But to be honest, the only way to really understand what I mean by all of that is to use Game Maker, Unity and Construct and write large-ish projects using them, which I know you guys don't really have time to do :/.

                  Load more comments (2 replies)