How do I Concatenate certain arrays

0 favourites
  • 8 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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!

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

  • 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

  • Try Construct 3

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

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

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

  • 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

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)