How do i use arrays?

Get help using Construct 2

Post » Tue May 22, 2012 7:14 pm

Guys, be sure to check the items listed for "Arrays" in the how do I FAQ.

There are already numerous topics on the subject with example capx in this, that or again this topics.

Active reading and exercising should help get the hang of arrays.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Tue May 22, 2012 7:15 pm

@Yann ok, this is the easiest bar of the array (the learning), ok the questions how can i set them on construct2 here is the problem .

sometimes i have global variable = 0 and sprite frame number,and my array is : at(global variable,sprite frame number)=0 ---> action = sprite destroy
**this can unlimited numbers of arrays that has value = 0...

this is diffrant between
array value = 0 ---> action sprite destroy

but the problem in 2nd one how can i store the things i want on it , for example i can make array with at(0,global variable) = 0 or
at(0,sprite fram number)= 0 , many stuffs like this...

but i found , the easiest way to store array values by doing like :
on start of layout ---> array (0,1) = 1
                        array (0,2) = 2
                        array (0,3) = 3
                        array (1,1) = 4
then in next event we do like this :
if array current value = 1 , spawn enemy1
if array current value = 2 , spawn boss1
if array current value = 2 , spawn enemy2
if array current value = 2 , spawn boss2
**the problem i couldn't get it on this way is how can i combine the array with the global variables i don't know the expression...



in all that stuffs there are more complex stuffs , and im having fun learning them.

the good point on arrays that if you want your game to be good you must have at least one array ... mostly one array is enough you can make 999999999999999 stuffs with it but some use more for organizing only.

zsangerous2012-05-22 19:23:52
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Tue May 22, 2012 7:40 pm

i see. So arrays are a way to organize your work. Cool. and I don't think jar jar binks would be considered an enemy hehehe, great tutorial yann.
B
22
S
5
G
3
Posts: 194
Reputation: 5,855

Post » Wed May 23, 2012 12:17 am

http://www.scirra.com/tutorials/307/arrays-for-beginners

I spent the best part of this evening on this tutorial. Let me know if there are any typos, errors, omissions etc.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Wed May 23, 2012 8:03 pm

The absolute best way to learn what arrays do and how to use em is to open up some kinda spreadsheet and start setting values. Each cell on the spreadsheet relates exactly to a location in the array.

A 1d array = a spreadsheet with just 1 column but however many rows you want
a 2d array = a spreadsheet with 2 columns and however many rows.
a 3d array = a spreadsheet with 3 columns and however many rows.

It really is that simple. Try to work with an array in c2 and at the same time have a spreadsheet open and use the spreadsheet to input your values you want in your array then you can use the exact locations of the cells to know where that value should be in your array
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Wed May 23, 2012 8:20 pm

[quote]A 1d array = a spreadsheet with just 1 column but however many rows you want
a 2d array = a spreadsheet with 2 columns and however many rows.
a 3d array = a spreadsheet with 3 columns and however many rows.[/quote]
1d is correct but 2d and 3d are more like this:
a 2d array = a spreadsheet with however many columns and however many rows.
a 3d array = a spreadsheet with however many columns and however many rows and however many pages.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Fri May 25, 2012 12:27 am

gonna check out that tutorial ramones.
B
22
S
5
G
3
Posts: 194
Reputation: 5,855

Post » Sat May 26, 2012 5:15 pm

[QUOTE=AarongamerX] I have a vague understanding of arrays. Could someone help me understand how they work. [/QUOTE]

Arrays are nothing more than more powerful variables. A single variable can only hold 1 thing. Arrays are variables that you can actually page though your data like a spread sheet.

How about this example. Say you had 3 monsters in your game and needed to know what their health was, and how much magic they have for spells.

Array.MonsterArray 2X3X1 makes an array that holds data for 6 things(2x3) forget the 1 for now.

               Health   Magic   
Monster1    10       3
Monster2     4       6
Monster3    10      10

So you woulds need a MonsterArray 2,3 to hold the data. Then for example if you wanted to know how much magic monster2 had you would look for":
Array.MonsterArray(1,1) and that would tell you it had 6 magic points.

*note arrays start at zero and count up so the first element would be 0 the second 1 and the third 2Guyon2012-05-26 17:17:25
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Sat May 26, 2012 7:47 pm

@Guyon @R0J0hound @aridale

the problem isn't in understanding array the manual understanding them so well even all tutorial do that but the problem how can i make them on construct2 this maybe the 5th time i have tried but still i lost :(

see this level page

http://dl.dropbox.com/u/67034121/forum/level%20page.capx
i tried to made but i really get miss with it , i wanted the win button to make sprite 2nd frame, and if clicked on finished it finish the seleceted or the last unlocked frame and make it 3rd frame of levels object. you gonna say this can be done with variable but the problem isn't in this the problem that i wanna see it in easy example to try to do it in harder one like levels has 1-3 stars , worlds and sometimes special levels....
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Sat May 26, 2012 9:04 pm

@zsangerous Hope this helps: levelSelect.capx

ramones2012-05-27 00:41:00
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: mercuryus, mystazsea and 18 guests