Hash table VS Private Variables VS Array

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm sorry if I'm asking a lot of questions but I'm trying to learn this engine as quick as possible before my midterm break finishes.

    Back to topic I'd like to ask; when I'm trying to store integers like the amount of a certain object is created and the maximum amount of that object should be created should I use Hash table or variable, or array? I know this is kind of low level stuff I should find out on the net but reading those stuff is too technical and I can't find what I want to know.

    I guess I could use array but I have no idea how real arrays work or to be specific store the information (damn game maker I curse you for making it too simple).

    Also would the choice still apply if I use whole lot more information, such as the value mentioned before but to keep track of multiple objects?

  • What are you trying to achieve? It is hard to visualise what you are asking.

  • Yeah a few more specifics would help, but from what you've described it doesn't sound like arrays or hashtables are necessary. You might want to just create a small object with a few miscellaneous PVs, or use global values (if you won't be using a lot).

  • for example

    I want to keep track of a sprite object (dots,balls, you get what I mean).

    More of it (instances I assume) spawns with time.

    I want to create a set amount that will increase over time too.

    Hence I thought of 2 variables to keep track.

    One keeps track of how many of that object exist and the maximum amount of that object should exist.

    So I thought I could attack 2 private variables to an object such as a text object.

    So I created

    DotCount :: variable that keeps track of actual amount

    DotCountMax :: variable that is the number of maximum amount that the sprite object should exist

    That's just one object. There's actually 3 more so...

    DotCount

    DotCountMax

    YDotCount

    YDotCountMax

    GDotCount

    GDotCountMax

    Each of these I use to keep in check how many of those objects exist. How I do that is when an event is executed the object/instance spawns in the layout and variable DotCount increases by 1 to indicate there's 1 more of that object in existence.Then DotCount is compared to DotCountMax to see if DotCount < DotCountMax, if so then the cycle repeats and instance is created again.

    If there's a simpler way then please do tell me.If not would using pv more manageable than the other ways? Or am I understanding this all wrong and infact hash tables and arrays are nothing like pv (I know arrays are different).

  • If there's a simpler way then please do tell me.If not would using pv more manageable than the other ways? Or am I understanding this all wrong and infact hash tables and arrays are nothing like pv (I know arrays are different).

    PVs on an unrelated object or global values would definitely be the easiest way to go. If all you're doing is comparing miscellaneous values then there's no need for arrays or hash tables; they're for more complicated stuff.

    For instance, arrays are basically a checkerboard (with added z dimensions if you want, making it a cube) where each square can contain a value - integer, float, string, container, what have you. If you want to write or retrieve a value from an array you have to figure out the x,y,z coordinates of the 'square' you want.

    Hash tables are similar but use "keys" instead of coordinates.

    Both are capable of being saved to a file, loaded from a file, looped through, and so on.

    (The wiki probably explains this better ^^;)

    As such, they would just make what you're trying to do unnecessarily complicated.

  • If there's a simpler way then please do tell me.If not would using pv more manageable than the other ways? Or am I understanding this all wrong and infact hash tables and arrays are nothing like pv (I know arrays are different).I would probably use global variables for this. Although, I'm not sure if you are aware of, but there's an expression that returns the number of instances of an object (Get number of objects), so you don't need to create your own counter depending on the case. You just need to use a System "Compare" condition and put it like "Sprite.Count < SpriteMaxCount".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > If there's a simpler way then please do tell me.If not would using pv more manageable than the other ways? Or am I understanding this all wrong and infact hash tables and arrays are nothing like pv (I know arrays are different).I would probably use global variables for this. Although, I'm not sure if you are aware of, but there's an expression that returns the number of instances of an object (Get number of objects), so you don't need to create your own counter depending on the case. You just need to use a System "Compare" condition and put it like "Sprite.Count < SpriteMaxCount".

    Ah I was looking for that in the editor but had no success. Thank you people for enlightening me on this area of programming. I just got better at it.

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