# How do I Concatenate certain arrays

Get help using Construct 2

### » Fri Oct 30, 2015 2:36 pm

I am creating an educational game that uses several arrays to hold the math problem and the possible answers. When the child starts the game, they can choose which math facts to practice. I have arrays created for each of them already. But, should the child want to practice their 2, 4, and 7 facts, I need to be able to concatenate the arrays into one "GameArray" that will be used to pull the problems from during game time.

I have read the Arrays for Beginners and dictionaries and everything I can find on arrays so far, but I am hoping there is some simple one action that says, GameArray = GameArray + Array2; or something like that lol

Any help would be great!
B
3
S
1
Posts: 9
Reputation: 348

### » Fri Oct 30, 2015 4:21 pm

Although I heavily under use Arrays...

Couldn't switch between picking from 1 array to the other? (This highly depends on how you pull them into your game)
Like randomly pick from each of the selected arrays...

PS: I've dabbled in the Edu games and would love to see what you come up with.
Eat ALL THE BACON!
B
47
S
17
G
3
Posts: 292
Reputation: 5,079

### » Fri Oct 30, 2015 6:53 pm

If the arrays are one dimensional (ex: with size (n, 1,1)) then you could do this:

start of layout
> gamearray: load from json string Array1.AsJSON
---- array2: for each x element
----> gamearray: push back array2.curvalue on x axis
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Fri Oct 30, 2015 11:58 pm

Unfortunately, they are not one dimensional arrays. Each array has a size of (10,7,1). It would be fine to just push in the elements of each array, if I could just figure out how to do it properly. In AS3 I would simply add each array to the game array and then choose randomly from there. But, thanks for the suggestion R0J0hound.

antares330, I am basically goaling to recreate the educational games that I have made for my site fun4thebrain.com. I have many many games that desperately need to be turned into HTML5, so I am tackling Construct 2 in hopes of rapid development. Since all the artwork is done, once I get the array situation figured out, I should be able to whip the games out. Fingers Crossed! lol

I will look into the idea of randomly choosing from the chosen arrays. Maybe creating an array of the chosen fact families, and then, when loading the problems, it could randomly choose from that array and go from there.... hmmmm... that might work. Doesn't seem pretty, but it could be functional. Thanks.
B
3
S
1
Posts: 9
Reputation: 348

### » Sat Oct 31, 2015 12:29 am

If you add a 3rd dimension to your array you can effectively have a "stack" of all the 2d arrays you have already created, in one big array.
I don't know if it helps at all, but if you imagine the 3rd dimension as a z index I guess you can modify your events to "pull out" the ones you want.
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

### » Sat Oct 31, 2015 1:47 am

This should do it I think. The "---" means subevent.

Start of layout
> gamearray: set size to (array1.width+array2.width, 7,1)
--- array1: for each xy element
---> gamearray: set at (array1.curX, array1.curY, 1) to array1.curValue
--- array2: for each xy element
---> gamearray: set at (array2.curX+array1.width, array2.curY, 1) to array2.curValue
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Sat Oct 31, 2015 2:15 am

hound, Oh my goodness! That completely looks like it should work. Let me work on it and I will let you know how it goes. Thanks!
B
3
S
1
Posts: 9
Reputation: 348

### » Sat Oct 31, 2015 1:24 pm

R0J0hound, this worked great! Thanks so much. Now that I see how it works, I can work on making it a bit more dynamic because I never know how many arrays the kid might choose.

One question though... if I looped through each element of each array, couldn't I just push that into my GameArray? I tried it, and it crashed Firefox lol but I thought theoretically it should work. If it did work though, I could just make a family of all the arrays and then whichever ones were chosen could be told to push their data into GameArray.

Anyway, I will keep playing with that, but thank you so much for this help!! I am so excited!
B
3
S
1
Posts: 9
Reputation: 348