How to find X of an Array?

Get help using Construct 2

Post » Sun Apr 30, 2017 4:32 am

I'm still a beginner with Arrays, but I was wondering how to pin point X based on a selected value?
Example, if i need the X value of "58" it would be 5
This 58 will also be sorted vertically, so I need a "real-time" value if that makes sense?

Would it be Array.CurX? or something?

Image
B
17
S
6
G
1
Posts: 79
Reputation: 2,422

Post » Sun Apr 30, 2017 4:56 am

CurX is only for looping through the entire array.

If you know your index you would reference it like Array.At(5)

but if you are trying to find the row based on a value, you need to loop through the whole array and look for it. So you would use CurX and CurY (because your array above is 10x10). You have to look through on each row (x) and then in that row each column (y).

Think of arrays like excel spreadsheets.. the rows are X and the columns are Y

Image

If there's more than 1 "58" in your table this loop will execute the action(s) for each "cell" that equals 58.
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Sun Apr 30, 2017 5:17 am

maybe I'm backwards, but isn't it more like.

(7,5) = (x,y) = 58 = (Array.curX, Array.curY)

so the x value of 58 is 7
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Sun Apr 30, 2017 5:19 am

Oh right, sorry haha i got it mixed up! yes should be Y = 5
B
17
S
6
G
1
Posts: 79
Reputation: 2,422

Post » Sun Apr 30, 2017 5:21 am

Man, this whole array stuff is soooo confusing
Hmm, lemme try another example.....

So, if I want to set (7,5) to "5" (which is basically its Y axis)
What expression would I put down?

something like..... Array | Set Value at (7,5) to..."Array.CurX"??
B
17
S
6
G
1
Posts: 79
Reputation: 2,422

Post » Sun Apr 30, 2017 5:33 am

click action, select array, click 'set at xy', fill out the form.

the tricky part is figuring out where to put the action, which will just depend on your specific game.
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Sun Apr 30, 2017 5:53 am

so you would make your array like this:
Image
B
25
S
16
G
26
Posts: 125
Reputation: 16,103

Post » Sun Apr 30, 2017 7:17 am

Just figured it out, thanks!!! :D
B
17
S
6
G
1
Posts: 79
Reputation: 2,422

Post » Sun Apr 30, 2017 3:33 pm

celstrider wrote:maybe I'm backwards, but isn't it more like.

(7,5) = (x,y) = 58 = (Array.curX, Array.curY)

so the x value of 58 is 7


the x is always the row.. so it really depends on the data and how you format it. If it's laid out like Excel, the X is horizontal.. that's how it is in other programming languages. With C2 it's weird to me how they say Y is height or rather horizontal rows.

I think of arrays storing data like this:

Code: Select all
John   123  y
Mary   392  n
Fred   495  y


instead of this:

Code: Select all
John Mary Fred
123  392   495
y    n     y
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Sun Apr 30, 2017 3:38 pm

cgsammu wrote:Man, this whole array stuff is soooo confusing
Hmm, lemme try another example.....

So, if I want to set (7,5) to "5" (which is basically its Y axis)
What expression would I put down?

something like..... Array | Set Value at (7,5) to..."Array.CurX"??


it's not a "Y axis", once your array has more than 1 column you need X/Y coordinates... if it just has 1 column, you only need X. You would need to do: Array.At(7,5) = "5". The CurX is the loop variable, meaning it starts at 0 and increments by one with each loop - up until there are no more array elements.

with one column:

here you use only X
Code: Select all
Array [0] = "john"
Array [1] = "fred"
Array [2] = "mary"


with more columns... (first name, last name, age)
here you use X and Y
Code: Select all
Array [0][0] = "john"
Array [0][1] = "smith"
Array [0][2] = 25

Array [1][0] = "fred"
Array [1][1] = "smith"
Array [1][2] = 21

Array [2][0] = "mary"
Array [2][1] = "smith"
Array [2][2] = 28
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests