A Question About Array Checking

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hey guys,

    I wanted to ask a quick question about arrays, Im going to learn this even if it kills me!

    I needed to know how i can check the cells around my array to find out if my ground sprite is exsposed to air from the top only and if so i wanted to change my frame to a grass covered ground sprite while leaving all other ground sprites that are not exsposed to air untouched.

    How would i go about setting an event up to check the left,right,above and below my sprites? This is a big deal when it comes to arrays im just trying to learn more on the subject.

    Thanks guys

  • Anyone Know this? I seen a few things on it here inside the forums but most was used for bitwise method which im not using im using arrays.

  • well, in the case of an 2D array that you go through, you could do a for each value (on X and Y), and test the value Array.At(Array.CurX, Array.curY-1) to test the cell right above for exemple (I do not know the exact context for you so be wary)

    however remember that outside of the array, the value of the "cells" is 0 (array.at(-1,0) returns 0)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank You Aphrodite thats all i needed to know, using the array is a method i need to burn into my brain.

    I just seen this reply sorry for the late reply. I just asked R0j0hound this question but maybe you can help me aswell.

    im having an issue with figuring out if the cell is empty because if my cell is equal to 0 and my animation frames adjust to the value of the array.

    dirt = 0

    grass covered = 7

    If an empty cell is equal to 0 that is giving me an issue because if it is empty it will always make the sprite that occupies that cell Frame 0

    What is the return value of an empty cell?

    Im kinda confused because the way i see the logic it seems like an empty cell should return a different value.

  • Thank You Aphrodite thats all i needed to know, using the array is a method i need to burn into my brain.

    I just seen this reply sorry for the late reply. I just asked R0j0hound this question but maybe you can help me aswell.

    im having an issue with figuring out if the cell is empty because if my cell is equal to 0 and my animation frames adjust to the value of the array.

    dirt = 0

    grass covered = 7

    If an empty cell is equal to 0 that is giving me an issue because if it is empty it will always make the sprite that occupies that cell Frame 0

    What is the return value of an empty cell?

    Im kinda confused because the way i see the logic it seems like an empty cell should return a different value.

    I believe that arrays start off with all zeros. If you wanted it to default with something that means "empty" to you then you could loop through the entire array right after you first create it and fill each cell with -1 or whatever you want to mean "empty".

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