Why does the event system use JavaScript?

As the question says above. Because I heard that JavaScript is not really a good language for optimization and performance. I don’t know if that is true, but why did they use JavaScript for the event system? (I am not trying to hate on JavaScript, just wondering the reason of using it.)

First of all, that is only somewhat true: JavaScript is not the most performant language, but it is fairly performant. There are also many many more factors to chosing a programming language than simply it’s performance, and the languages more performant than JavaScript have a lot of flaws in all of those other factors.

It’s also noteworthy that the events system doesn’t “use JavaScript”: it is completely language agnostic, and the code generation is provided by extensions that can be made for any language. In fact there exists one for C++ in addition to the one for JS, although you won’t be able to use it.

With that out of the way, there are many reasons to using JavaScript:

  • The web platform: JavaScript is the base language of the web. The web is so widespread that you can run a web-based application on all devices without word platform specific bugs. This allows to make games that can run in the browser and everywhere else with a single version of the engine, no platform-specific code, with the guarantee of consistency.

  • “Move fast, break things”: That is a famous quote that we took to heart. We want to move fast, and JavaScript has many attributes that make it fast and easy to add in new features, do modifications and test them, allowing GDevelop to be often updated.

  • User friendliness: JavaScript is one of the easiest languages to learn, use and understand, making dropping back to JavaScript events or modifying the source code of GDevelop when necessary much easier for users.

  • No crashes: JavaScript is a very forgiving language that can never completely crash. With it, we never have a truly fatal error, even very bad ones can be recovered from most of the time. This allows GDevelop to stay very easy to use as you never have to deal with weird and hard to debug crashes and errors, and have a resilient game.

There are many more reasons but those are among the most important ones.

2 Likes

Thank you for your clarification. I heard that some people hated it that GDevelop was JavaScript based, and I was wondering why they were hating the JavaScript usage of GDevelop.

Never heard of anyone hating on GDevelop for that reason :person_shrugging:

1 Like

In the early days when GDevelop dropped the C++ codebase and transitioned to JS, HTML5 support was really poor on mobile devices and building HTML5 mobile and desktop apps required to use 3rd party CMD tools which was troublesome to use especially to interface with 3rd party APIs. At this time build services was also not free or they did put limitations on project size, build times…etc
GDevelop had to also drop features in the early days such as 3D boxes, lights, particles, tiled maps, spacial audio, xml support and maybe more.

For that reason alone some people did spread negativity on the forums and left the community.
It is possible you are going to find some of this old conversations and complaints on the forum, but as arthuro555 explained, it has changed and JavaScript offer lot of benefits and it is well supported on all platforms now. GDevelop also has many of the previously missing features now and even more.

With JavaScript developers need to implement a feature only once and it works everywhere while other programming languages like C++ require to implement features for each platform which is a lot of work. This is why the industry is transitioning to cross-platform solutions like JavaScript.

Big studios continue to use C++ of course because despite everything C++ is a lot faster than JavaScript and they already have the developers, experts and codebase. They have no reason to drop C++ and it would be also very expensive for them.
But for small studios, individuals starting today, JavaScript is a better option.

Now if we are talking about the JavaScript events and why there is no C#, Lua or other events.
JavaScript events was originally added only as an experiment to expose the internal JS components to the events that otherwise not accessible. It was never meant to be a primary way to use GDevelop but to be able to experiment with new features like the 3D extension for example. Now thanks to the JS events, we have this 3D experiment going and one day it may become part of GDevelop and this is what the JS events meant to be used for. Rapid prototyping and experiments. Nothing more.

Of course as the user base is growing, the demand for a more beginner friendly scripting API like GDScript and GML also going to grow but it would go against the core principle of GDevelop which is developing games without code. Making the event system even more flexible, more capable would make more sense in my opinion than maintaining any kind of scripting language as the primary way to develop games.

2 Likes

Thank you for your explanation.

yeah, JavaScript is so easy even someone as daft as me can learn it. :woozy_face:

The funny thing is that most of the rare crashes we have are due to the C++ code we use for the core game engine (herited from GD4), due to the difficult memory management in C++. If you miss to free a memory slot, it can crash.
That was the most fun thing^^

Having Javascript means we don’t have to worry about it because it’s already taken care of pretty efficiently.

Now there’s some crazy 3D in Javascript.