Advanced minification question

0 favourites
  • 9 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • I have everything pretty much working with advanced minification in my game except for one issue. My whole game is pretty much in javascript except for some touch events that then call into the code.

    I have implemented a pseudo entity control system in my game where I just assign components to my entities and I have an algorithm that can find any entity with any combination of components to act upon in the systems classes. One of my systems is a movement system and it handles moving anything that has a movement component attached to it.

    All of this works fine with no and simple minification, but not with advanced.

    The issue is I use es6 functions to iterate over, reduce, and flatten the final result of the component search. To do this I am iterating over the complete object collection as such Object.keys(this.runtime.objects). Under anything but advanced minification this returns an array of all properties on the objects object. In advanced minification it returns an empty array.

    Is there something happening during advanced minifcation that prevents the properties for the objects collection from being iterated over ?

  • I believe I found the answer. The properties must be set as non-enumerable during the minification. If I use Object.getOwnPropertyNames() instead I can access all of the properties and everything works correctly.

  • Thanks for the tip! How was the experience of doing all of the game in JS vs using events? Better perf? Faster dev? Other?

  • Hmm, advanced minification shouldn't affect the enumerability of properties. Can you make a minimal example demosntrating the problem?

  • Ashley

    Here is a small example project that shows the behavior.

    I am using :

    chrome: 78.0.3904.108

    Construct3: r178

    If you run the example you will see in the console three object iterated over. If you perform an advanced minification, HTML export, on it you will see the count of properties iterated on the object are 0. If you change it from Object.Keys to Object.getOwnPropertyNames then it will work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Mikal

    Just like anything there are pluses and minuses to either approach. I have had success with using the event sheet but I always reach a point where, to me, it seems convoluted to try and accomplish some tasks.

    I am a programmer so javascript is definitely more natural for me. I don't think performance is really an issue because you can optimize events pretty well and you can do the same with javascript, you can also write inefficient javascript code. You definitely have more control with how you accomplish things in JS, but that opens it up to any issues really falling on you as the developer.

    The biggest pluses for me with using JS are that debugging the logic is much easier for me using the chrome debugger than using the construct debugger. However, the info it provides such as utilization and FPS are awesome. Also being able to utilize functionality that isn't available out of the box is a good use for JS, whether you game is just using a little bit of it or the whole application is in JS. In my game I am able to manage users and store there current state object utilizing the PlayFab service api.

    The big downside to JS in construct is that there isn't a full blown development environment. It does provide excellent auto completion and syntax checking, but there aren't ways to search all files, refactor the name of a class and have it automatically rename all instances, find all references of a token, etc... So if you aren't careful with how you layout your code you can have a hard time finding things later on.

    Overall I think it depends on what you are comfortable with, your experience with JS, and whether your game can benefit from a little JS or a lot of JS.

    I have been programming in JS, C#, C++, and others for many years and find it easier for me.

    If you have any additional question, just let me know.

  • Thanks for the comments, that all makes sense. Good to hear about the experience. In terms of the development environment, yes I hope that someday we can use an external editor at least for the JS files included in the project.

  • rhg1968 - can you post that to the issue tracker so it's not lost in the forum?

  • Ashley

    I just submitted it, thank you

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