0 Favourites

What's the use of an array?

  • Can someone give me an example of a practical use for an array in a game?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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!

  • Arrays are group of variables. You can use array to make for example high score for each level .

  • Can someone give me an example of a practical use for an array in a game?

    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'

  • 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.

  • Thanks all your answers were very explicative!

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)
Similar Topics Posts Views Last Post
Unread hot topic
217 18,531
humanescape's avatar
humanescape
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor
Unread hot topic
0 Favourites
[plugin] 3D using Copperlicht
72 25,983
Reken's avatar
Reken