A Question About Array Checking

Discussion and feedback on Construct 2

Post » Tue Dec 09, 2014 11:24 am

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
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,378

Post » Tue Dec 09, 2014 1:40 pm

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.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,378

Post » Tue Dec 09, 2014 3:50 pm

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)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Tue Dec 09, 2014 7:07 pm

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.
GMO FOOD = DEATH
B
23
S
9
G
5
Posts: 567
Reputation: 6,378

Post » Tue Dec 09, 2014 9:35 pm

RookieDev wrote: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".
B
21
S
5
Posts: 196
Reputation: 1,984


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests