Hash table VS Private Variables VS Array

For questions about using Classic.

Post » Tue Aug 30, 2011 4:03 am

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?
B
3
G
1
Posts: 44
Reputation: 563

Post » Tue Aug 30, 2011 4:38 am

What are you trying to achieve? It is hard to visualise what you are asking.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Tue Aug 30, 2011 6:04 am

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).Tokinsom2011-08-30 06:07:43
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Aug 30, 2011 10:02 am

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).
B
3
G
1
Posts: 44
Reputation: 563

Post » Tue Aug 30, 2011 12:36 pm

[QUOTE=jangsy5]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).[/QUOTE]

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.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Aug 30, 2011 7:10 pm

[QUOTE=jangsy5]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).[/QUOTE] 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".
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue Aug 30, 2011 10:55 pm

[QUOTE=Animmaniac] [QUOTE=jangsy5]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).[/QUOTE] 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".[/QUOTE]

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.
B
3
G
1
Posts: 44
Reputation: 563


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests