JavaScript and why I struggle to code in Construct

0 favourites
  • 10 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hello everyone,

    I dive into javascript gamedev course LEARN JAVASCRIPT IN CONSTRUCT made by Ashley, and despite how well it was explained and written I have the feeling that it's simply not enough for start coding a game in Construct.

    I am using GameMaker Studio, and I was hooked by marketed "The Gamemaker alternative" and blog "HOW JAVASCRIPT BEATS GAMEMAKER LANGUAGE".

    Okay, I get it, when you put it on paper it has faster performance, but still, it's not helping me to understand how much faster it is for me to code in construct. To make myself more clear, I opened scripting examples like Ghost shooter. I understand what operators are doing, how functions work, same thing as in GM, but everything in between is unknown to me. Grammar in GM is so simple and it's easy to follow. When I open Shootng code example I was scratching my head.

    for an example

    runtime.layout.addEventListener("beforelayoutstart",
    () => OnBeforeLayoutStart(runtime));
    	
    	// Attach the tick event to run the game logic over time.
    	runtime.addEventListener("tick", () => GameMethods.Tick(runtime));
    	
    	// The player fires bullets when clicking, which is done in a mousedown event.
    	runtime.addEventListener("mousedown", e => GameMethods.OnMouseDown(e, runtime));
    	
    	// Restart the game when pressing spacebar if the player was destroyed,
    	// which is done in a keydown event.
    	runtime.addEventListener("keydown", e => GameMethods.OnKeyDown(e, runtime));
    	
    	// Create a new monster instance every 3 seconds.
    	setInterval(() => MonsterInstance.Create(runtime), 3000);

    Pardon my french, but there is so many coding for something so simple and not explained in javascript course. And on the other hand in gamemaker this passage would be much shorter.

    This is a big deal breaker for me, reason why I feel discouraged to code in Construct: there is no explanation of real game example - not running a code in a console - there are plenty tutorials and books on that, but a clear explanation why certain things are running the way they are in construct game. When "runtime." and everything that goes after "." is being used, same for "* as", "() =>", "e =>", etc. etc.

    I understand that shooter example was just that, example, what it can be done, and that's great, but what about making a game dev course of making a simple game, like Pong, and dissecting the code there, especially parts of code that will repeat in almost every construct game, and I am not talking about operators, but why sometimes is "runtime.addEventListener" and sometimes it's "runtime.layout.addEventListener", and that sort of things, things that were quite different from coding in GameMaker Studio.

    Sorry for long post and my rant, I really want to use js in construct but I don't want to use it to run text games in a console but actually to make a visual game and therefore I need to understand how to use JS in that scenario.

  • But have you tried events, and are comfortable with that method?

    Its one thing if you wish to get used to coding with JavaScript, but it was never meant as a full replacement to events. It should be thought of as the proverbial hammer when the regular methods won't do imo.

  • But have you tried events, and are comfortable with that method?

    Its one thing if you wish to get used to coding with JavaScript, but it was never meant as a full replacement to events. It should be thought of as the proverbial hammer when the regular methods won't do imo.

    Yes, of course, visual scripting in Construct is way better than in GM no question about that. But I like to code, easier to keep things in order. And since Construct is marketed as a superior software than a GM to code a game, all I am looking is better explained how the code works in the actual game. Would be nice to have some game example deeply explained, like, you have learned the basics of js now let's learn how to put all that in a game (endless runner, platformer, arcade, whatever) and explain how things work there and in which order. It's not just declaring variables and calling the functions, there is some order that needs to be followed; create events, step events, calling objects, changing sprites, changing instance variables, adding and editing behaviors in that hierarchy, and so on...

  • There might be more official examples eventually, but their plate is pretty full.

    Ashley could have with more of those first, but the tutorials make more sense, chicken and egg wise.

    Then you shouldn't expect a great deal of examples of full games from the community for the same reasoning in my first post.

    Edit:

    I should add that you can always ask for help on the forum.

    A full game example might be too much, but plenty of people will be willing to help with parts you don't get.

  • The "Learn JavaScript in Construct" tutorial is still a work in progress - there are several more parts to come and it will cover more of the things you've mentioned.

    The guide also already covers some things like how => is another syntax for functions. The most recent part does also cover (albeit in brief) how addEventListener is a standard way to listen for events in the JavaScript ecosystem: for example document.addEventListener("click", func) means func will be called every time the user clicks anywhere in the page.

    This is all the usual way things are done with JavaScript, including in browsers and other environments like node.js. So while there may be a learning curve as many of the patterns and APIs will differ from GameMaker, you're learning the real-world patterns used widely in industry, which is a really useful transferable skill.

    Further many of these patterns are very powerful and allow for complex and sophisticated code that can make things easy that are currently awkward in GML. For example async functions make it far, far easier to write async code. However that does mean, naturally, learning about how async functions work in JavaScript, but again this is all industry standard stuff so you'll be learning real-world programming skills, rather than one tool's specific way of doing things.

  • I agree that this tutorials are helping ppl (me included) to learn and understand real-world coding patterns in js, however I would like, I guess other ppl new to js as well, how to transfer those patterns in a real game. So my question is, will there be tutorials where you can transfer and explain all that knowledge in a real game? Like ppl are usually making for unity, appgamekit, GM... starting from declaring variables, then making start/step events, etc. Basically a Step by step totorial how to write a game using js and construct.

    Thanks for your time Ashley, for replying on my post

  • I'm definitely not the best dev in either JS or Construct, but I do work with both a lot, so I'd recommend trying to build tiny systems in the Event Blocks and then trying to remake them in JS, it should help you break apart patterns and tools.

    Also how a problem is small and more focused, influences on how easy it will be to get help or find previous solutions.

    I don't how much this is helpful, but I hope it is.

  • I'm definitely not the best dev in either JS or Construct, but I do work with both a lot, so I'd recommend trying to build tiny systems in the Event Blocks and then trying to remake them in JS, it should help you break apart patterns and tools.

    Also how a problem is small and more focused, influences on how easy it will be to get help or find previous solutions.

    I don't how much this is helpful, but I hope it is.

    Any kind of advice is helpful, thank you

  • it'S also kind of like,

    the documentation was written by someone who already knows how things works,

    for someone who already knows how things work,

    as kind of a refresher or reminder,

    and it's almost useless for someone trying to learn,

    so a lot of us struggle and get frustrated

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I appreciate it's important to have lots of good documentation on coding in JavaScript for newcomers and more would be useful. The main limiting factor is just that good quality documentation is time consuming to write. The current in-progress "Learn JavaScript in Construct" tutorial series is a months-long project, and there's probably several other similar tutorial series we could potentially write on coding various aspects of different games. We'll work on it, but it will take time. In the mean time it would be great if any other users who've learned some useful things about JavaScript coding could share what they've learned in the tutorials system - part of the reason it's there is so everyone can share their own tips, tricks and guides, both for the event sheets and coding.

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