What's the use of an array?

Discussion and feedback on Construct 2

Post » Tue Nov 18, 2014 8:11 pm

Can someone give me an example of a practical use for an array in a game? :mrgreen:
B
66
S
22
G
4
Posts: 360
Reputation: 6,584

Post » Tue Nov 18, 2014 8:19 pm

I advise you to check the tutorial 'arrays for beginners'.
It doesn't explain everything about arrays, but does cover a whole lot!

Good luck!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Tue Nov 18, 2014 8:22 pm

Arrays are group of variables. You can use array to make for example high score for each level .
ImageImageImageImageImage
B
56
S
15
G
5
Posts: 852
Reputation: 11,446

Post » Tue Nov 18, 2014 8:45 pm

Danwood wrote:Can someone give me an example of a practical use for an array in a game? :mrgreen:


Arrays are probably the single most powerful construct in any programming language, including C2. The following are just trivial examples.
A 1D (1 dimensional) array can store (and allow you to easily retrieve) a list of numbers or text.
A 2D array is like a grid and so is good at storing, e.g. a level full of things that you can easily access via x,y coordinates.
3D arrays are useful but less common IMO, you might use them to extend your 2D levels to have floors as well :)

They are powerful because you can go through them in a 'loop', rather than one by one. Or grab one randomly by its 'index'
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Nov 18, 2014 9:34 pm

You use arrays when you want to store multiple variables and variables relating to those variables. This makes it great for things like Level editors where each enemy or object can have its name stored in X and all of the information about it stored in the Y's (it's position, angle, starting health, animation, or whatever you want). I also use arrays for dynamic lists like in multiplayer by using them to determine which player is trying to send a chat message to whom. it works with just X values and uses position 0 for the senders name, position 1 for reciever, and position 3 for the message.

The sky is the limit for how complex their use can become, but in general, they are for large sums of data handling or dynamic lists.
B
20
S
2
Posts: 70
Reputation: 1,466

Post » Tue Nov 18, 2014 11:07 pm

Thanks all your answers were very explicative!
B
66
S
22
G
4
Posts: 360
Reputation: 6,584


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests