Nestable hashtable plugin & object sealing?

0 favourites
  • 4 posts
From the Asset Store
Hungry Seal – Construct 3 & Construct 2 - Easy editing
  • Hey all, :)

    I just started building a plugin that provides a hashtable for witch each key can be a number/string value, or it can reference a deeper hash table. Because each hashtable can have keys that link to other hashtables, you can have an arbitrarily deep tree of hashtables and data.

    My concern is that I just remembered something about object sealing in the runtime.

    Will sealing prevent this plugin from working?

    In my plugin's runtime, in the instance class's onCreate() function, I'm only creating one property to hold the root hash table, named "rootHash".

    All other modifications to the data structure from then on are done to rootHash, via C2 events/actions. That includes the addition of keys, and the creation of deeper hash tables.

    I'm trying to understand if that kind of modification is possible, or if sealing the object restricts what you can add to it, or restricts what you can add to sub-objects.

    I'm hoping that as long as I don't add more properties directly to the instance class (which I'm not) I should be okay.

  • In my experience object sealing hasn't affected my code at all. Not sure if it's because it's not being done or something, but I'd say just go forward with your plugin and if you get to the point of it not working because of sealing then look for workarounds.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Object sealing is shallow, so if you have a root property, you can dynamically add and delete properties from that property.

    Adding/removing properties dynamically can reduce performance in modern JS engines, so the engine tries to enforce static object properties by sealing objects. I think we eventually turned that off though due to sealing ironically having a performance impact on some other JS engines Still best practice is to keep a static set of object properties. For a dynamic data structure though there's no problem with adding/removing properties, since that's what it's for.

  • Thanks R0J0hound and Ashley for the suggestions and info.

    Sounds good.

    I have gone ahead with building this plugin, and it seems to be working correctly so far.

    As it happens, the root object's properties are never removed or added to, as all the dynamic stuff happens inside a permanent property named "rootHash".

    So it sounds like that should work.

    I'm ultimately hoping to make a behavior version of it as well, so I can have per-instance dynamic data structures.

    Also, sorry R0J0hound, for some reason I thought I posted a "thanks" reply a day or so after your response. In any case I did take your advice, so thanks.

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