# arrays

0 favourites
• 14 posts
• hmm today i have a question about the arrays,

ok ,before you give me manual links,tutorials i found all arrays are hard to understand.or they have specific use.

the things i want to know:

1) what the arrays used for ??? for example in level manu,in score,....i don't know the use of it , if they are many tell me the best uses.

2)how to use arrays also what does width mean, hight , depth.

i don't know even if i change the width nathing happen , why i can't put 0 what does 1 means?? i know its none-zero value but why???!! what does hight used for?? hight or what?....

3) if you have any questions or answers about arrays post it her with .capx please i want to see examples , the forum has really few examples.

i have more questions if i got the answers of these ill ask , thanks for help ^^ i wish there is a competition for making tutorials so..

videos contest,tutorials will help construct2 alot... good luck^^

• oncrete commented example of use of arrays - LINK

From the how do I FAQ section "Arrays" that you should really check each time you make a search since it contains lots of answers to the frequently asked questions like those, the capx in the topic will show you how to properly use an array, hopefuly in a comprehensive way.

Also be sure to check the manual article about arrays.

An array is a structure in memory that allows you to keep values.

Contrary to a global or local variable which can hold only one value of one defined type at a time (number or text), an array is composed of cells, each one of which can hold values of wether type.

Those cells can also contain a dimension of the array.

Width is the X size/index, Y the Height and Z the depth.

Those are the coordinates of the cell in a 1D (only X), 2D (X, Y) or 3D (X, Y, Z) array.

This means that a cell from index X = 0 can contain more than one cell at Y and Z. (Check the tutorial again as well as high school mathematical notions)

An array makes it also easier to access/manage/loop through the cells

Hope this helps you figuring out a bit more the use of arrays.

• thanks ill check all links , but another question can i use more than one array?? the array is only connecting with the size of the window or can be connecting with sprites?also how i can connect the array with sprites?

• You don't connect an array with sprites or windows.

As I said it is a memory structure, it is a non world plugin (meaning you don't see instance to it in the project like the mouse plugin for example) that contains values.

Where those values come from and where to attribute them is up to you.

The width/height/depth have nothing to see with the visual plan (window/layout/whatever), it is just the "size" of the array.

An array of 5 width will contains elements from Array.at(0) to Array.at(4) (arrays index are 0 based, 5 elements have index 0, 1, 2, 3, 4)

An array of 2 width, 3 height will have those coordinates/cells available to store/provide values :

Array(X, Y)

Array.at(0, 0)

Array.at(0, 1)

Array.at(0, 2)

Array.at(1, 0)

Array.at(1, 1)

Array.at(1, 2)

Check the 2nd part of the tutorial linked above (after the loop, the author speaks about the arrays with nice comprehensive illustrations)

You can have several instances of the same array and you can have different object type arrays (for example, one array for your characters, one array for the NPCs, one array containing the dialogs of the game, etc...)

Just have a look at the links and take the time to assimilate them and understand the tools provided by the array.

It requires a bit of abstractive thinking, but once you get used to it, you're good to go.

EDIT: Have a look at this other commented capx which show you how to create instances of a sprite and attribute its instance variables values according to the values stored in an array (and shows also a lot of picking).

• I find the best way to think of Arrays is as an (Excel) spreadsheet - you have your columns and your rows, and each square (or 'Cell') contains a piece of data you want.

So in Row 1 in Excel I might have the scores of each level, with each level being in a different 'Cell' (Level 1 in Column A, Level 2 in B etc.).

The Array's Width basically coressponds to how many, in this case, levels that I want to save. So if I have 10 levels in my game for which I want to save the scores then I would set the Width of the Array to 10. The Height in this case I could leave as 1 as I only want to save scores.

If I wanted to also save, for instance, the time it took for a person to do my level then I would save that in Row 2, with the same Columns (A, B etc.) for each level as before. I would have to make the Height of my Array '2' to do this though as I now have two rows of data.

In Arrays though letters aren't used, and are also numbers. So if I want to access/store Level 2's Score, then I would want Cell B1, which in terms of the Array would be X = 2, Y = 1 (two columns across on the first row).

I realise this analogy is slightly useless if you've never used Excel, but it's how I tend to visualise it =)

I'm also going to upload a .capx at some point showing how to save/load Arrays to Webstorage at some point as I haven't seen a tutorial on this that doesn't used plugins.

Hope this helps!

• The excel sheet is indeed a good analogy for 1D and 2D arrays.

3D arrays are a bit trickier, as it is one dimension deeper ^^

I must admit I rarely use 3D arrays, mostly 2Ds/1D.

I guess this topic will join the other elements of the "Array" section in the how do I FAQ <img src="smileys/smiley1.gif" border="0" align="middle">

EDIT: Also still in the how do I FAQ I had made this mini RPG example using leveling and arrays with full comments.

When searching use the forum search and be sure to check the how do I FAQ.

There are examples all over the forum/site for you to check out, but YOU have to look in the right place.

• hmm i'm alittle understanding them , but the problem is in expressions its hard to write them and stuffs like that , in these hours ill try to do something if i made it wrong tell me why it is..

the thing i want to do it ( players page ) in this page there is a player if i clicked on him with left-click by mouse it change me to the other player (or 2nd frame because it isn't animated) and another click it change me to 3rd, after the 3rd if i clicked on it, it will return to the first player..

i think this just array(x).

by the way thanks to Kyatric

your RPGmini are really good , and hard to understand , but im trying to understand everything on it.

you really helped me alot to understand it.

but i have a question does the array take much time to do it, i mean does it take 3-5hour or more?? or 1-2hour because you know it well??

i want to rate my job as newbie or pro ^^ really thanks again.

• hmm after 1 hour working i sticked here :

http://dl106.herosh.com/a19c5e51c08ede97dfb9c55900dba576/array.learning1.rar

see capx, the problem when i click on the player 5 times and then 5 times then it stick and doesn't work again why??

• ## Try Construct 3

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

Construct 3 users don't see these ads
• You could save that in an Array(x) as you said, but for something that's only really storing one variable there's no need to use an Array, and you can simply use a Global Variable or, in your case, just compare the current Animation Frame of your character.

Arrays are more used for saving lots of data quickly, such as scores, whole levels etc. You can use them instead of variables, but there's often no need.

I'd take a look at your capx, but the link isn't working.

Regarding how long it takes, not very long at all once you get used to it =)

• thanks but i don't know , i want when i choose a player (frame) this frame comes in the whole game in all levels.. (to explain)of course there is a play button in the player page so i choose player then i click play then this player will be in all levels.

dl.dropbox.com/u/67034121/forum/array%20learning1.capx

• zsangerous Here you go:

You really don't need an array for something like that, it's more for saving large amounts of data.

• sorry the links not working :(

hmm how can i make the choosen player from play page is the main player for all levels?? i don't know if you understand.

• zsangerous Sorry, link is fixed now. And I've explained how to do that in the comments of the capx =)

• thanks for the big support from all of you guys, im making an easy game for now , in the future i wish i use arrays in a good way ^^ seems my new game doesn't need array except if i do a level page ^^ ill do it later ..thanks again :)

• 14 posts