Every new example I downloaded had weird code? Twice it declared engine & scene? No "use strict";

The examples I downloaded seemed to all be exact copies of each other, tabs were horrible, engine and scene were declared twice?
Minor problems including why do you not “use strict”; ? It is 2021?
I included “use strict”; which introduced an error I quickly fixed.
In the last few days I have downloaded all packages, installed Node.js, NPM, and tested all examples I got to work, mostly without the internet.
I then installed Node.js server based on an article I read that you wrote.

Thank you. I am only reporting a few simple fixes which apply to every example I downloaded.

Regarding engine and scene, are you speaking about official examples you get from the image button? If yes, could you give the faulty PGs so we can fix them?

Else, the PGs are created by people and so can contain mistakes. You just have to take them with a bit of a grain of salt.

Please clarify where you found these examples and exactly what you downloaded.

Hi, yes they were official sample codes for every sample almost.
I downloaded 14 samples and am studying and rewriting them to the way i like code, as far as tabs, margins, …https://playground.babylonjs.com/#KBS9I5#94, at least 12 I know have very sloppy tabs and the double declaration of engine and scene, plus the same function in the createDefaultEngine?

Many have the same function being called in the try and the catch, createDefaultEngine() I think. I do not understand this, same function, but maybe there is a reason.

I have been awake 48 hours studying this game engine, I am the type of obsessed computer programmer. It helps be see bugs and uderstand how the code works.

Take care,


James Lynch

213 222-3550

@Jim as @Evgeni_Popov said the playground is an area for users to try out coding in Babylon.js, give live code to get help in the forum and also to provide working examples in the docs. The docs themselves are open source and can be added to via a PR by interested users and so can vary in writing styles. However you are talking about the playgrounds after they are downloaded rather than the contents of the playground themselves.

A playground gives users the opportunity to try out and concentrate on Babylon.js without worrying about the the HTML and JS code needed to get it to work on the web, initialise the engine etc. all this is done in the background. The minimum wrapper to make a playground into a working web page can be found at Getting Started - Chapter 1 - First Web App | Babylon.js Documentation.

When you download a playground a wrapper, to turn it into a working HTML document, is automatically added and the formatting of the automatic code may not match the user written code. Downloading a playground provides you with the scripts needed to quickly view the code locally and to edit the code as you wish. It is not meant as an example of a fully formatted code layout. For example, having downloaded a playground, you might want to try out your own function to create the engine with a different set of parameters. You can then do that easily by adding your own createMyEngine function and the code that repeats createDefaultEngine then becomes

initFunction = async function() {               
      var asyncEngineCreation = async function() {
                try {
                     return createMyEngine();
                 } catch(e) {
                    console.log("the available createEngine function failed. Creating the default engine instead");
                     return createDefaultEngine();

This way if your create engine function fails the default engine will still load.

When you add to or edit a playground and then save it, its reference key at the end of the URL increases by 1 so a series of similar playgrounds may have much of the code in common see Playground | Babylon.js Documentation

Hope that answers some of your questions.