There's something I can't wrap my head around.
Don't understand why loopindex is sufficient for increasing the x index of a 1d array (when using Repeat X Times to fill or access data from the array and theoretically 1 spawn), but when doing a 2D array and 2 different spawns you have to increment loopindex by a variable for both spawns.
So something like X=0, and then
Repeat X Times
loopindex + X for first spawn
loopindex + X + 1 for 2nd spawn
Set X + 1
(for looping through the x indices)
I mean conceptually it makes sense, but this threw me for a bit of a loop initially because I thought for a 2D array this should work for 2 different spawns:
loopindex for first spawn
loopindex +1 for 2nd spawn
I mean, why wouldn't the natural loop index increase of a loop take care of these things in a 2D array, when it does in a 1D array for 1 spawn?
You don't want to add anything to loopindex, as it correlates to your array x index. If you want to set data for your second row, you need to add an action set array at x y, where x is loopindex and y is 1.
That does not make sense.
I'm not setting anything, just accessing data.
My point is access through the x indices seems to be completely different for a 2d array vs. 1d array.
I don't know if it's a programming bug or if I'm missing something else.
Develop games in your browser. Powerful, performant & highly capable.
To access an element in a 2D array you need two indicies, X & Y. One loopindex can't cover both values.
I realize that buddy.
Mine is a conceptual point (the code works, I just don't understand why it has to be different).
Basically I'm accessing 2 different numbers from a 2d array (yes, by using the appropriate x, y1 or y2 indices) and rather than having to use:
loopindex (1st number)
loopindex +1 (2nd number)
I have to use:
...which did not seem intuitive to me at all based on my 1D experience (with which you helped enormously).
Admittedly, I never tried accessing 2 numbers at a time from a 1D array, so I only know loopindex works (I don't know if loopindex+1 would work) in the same Repeat loop.
I'll try to post a capx eventually.
I have a weird bug with a 0 value/0 spawn in there too I can't track down and I was always able to figure these out before.
I guess another helpful question would be, how does Construct 2 compute the loopindex, say for the x index, in a Repeat X times loop and does this differ across array types and when accessing more than 1 number at a time?
In a 1D array, this seems fairly straithforward, at least for accessing 1 number at a time.
But what happens when you want to access say 2 consecutive numbers from a 1D or 2D array in the same repeat loop?
I haven't tested this yet in a 1D array and I couldn't find much on the internal workings of the loopindex.
1 post apparently states you can get the current loopindex via the loopname and something else, but how to do it was beyond me.
And apparently this is internal in at least some other programming languages, so you'd have to program your own counter to figure out what the loopindex reads with each iteration of the loop (to use it properly or at least figure out how the Construct 2 code works).
Err, I figured this out.
I was dozing off when it came to me.
The loopindex is 0 based (it has to be since regular access of 1d array works), so:
loopindex 0 1 2 3
x index 0 1 2 3
x index1 0
x index2 1
x index1 1
x index2 2
loopindex + 2
So the code makes perfect sense.
Guess, I'm just a newbe .
And again, I'm talking about accessing 2 consecutive numbers at a time from an array in a loop (matched pairs in this instance).