[solved] "use strict" messes with my JS code

Hello all.

Is there a way to remove the “use strict” (automated way - not by editing the code0.js file) that gets injected in the JS code when exporting the project? It really messes up with my code and gives me reference errors.

Well you shouldn’t have to remove it, if you do you are probably using very old or hacky code, which you don’t want to use in any serious game, and if you do not know how to fix the code to work in strict mode you probably shouldn’t be using JavaScript events in the first place as they are meant for people who know what they are doing.

Anyways, you can disable strict mode for a JS event by going into your project json file in a text editor to the part of the JSON that stores your JavaScript event, and there there is a boolean variable that you can flip to disable strict mode.

Thank you for the tip arthuro555, I will go through the JSON file and disable the strict mode.

I tried making the code compatible with strict mode but the problem is that the game needs to access the code and the code needs to access the game stats (setting variables) at the same time. I couldn’t get them both to work.

The code is not old and anything weird. I am trying to use a cordova plugin for my game. I was thinking that if GDevelop let’s you code in JS as well as in it’s own block-based language it should have a better way to handle external JS code.

Not quite sure what you mean by that, but it certainly doesn’t sounds like disabling strict mode is the correct solution.

I’ve used Cordova plugins in GDevelop multiple times and I don’t see what problem you could have using those, as they work exactly as one would expect, with no difference whether GDevelop or not :man_shrugging:

While GDevelop allows you to do anything you can do in events and more in JavaScript, JavaScript is in no way a main scripting method. You can “use JS as well as it’s own block-based language” but GDevelop and it’s API is made to allow for optimal usage through events. In your case, your issue sounds not bound to the API of GDevelop but more like a lack of experience with JavaScript (rather than GDevelop being limited).

Disabling the “strict” flag in the game json file makes the JS code work properly - no more reference errors. I was removing this this by hand before building the game with cordova but it’s better to have this done automatic.

Not my first cordova plugin either. Strict mode always seems to mess with the JS code.

Yes, I’m not experienced with JS, but I get things done. Not sure where the problem is, still it’s not easy to use external libraries in GD.

I just went through this exercise trying to integrate qrcodejs into a gdevelop project. The module is about 600 lines and does not work with strict mode. I would much rather turn off strict mode than try to refactor the entire thing, unless there is some other way? It would be nice to have a switch in the gdevelop editor instead of having to edit the source files.