ignoring array index values before the current one
I am reading an array to lay out my enemies as my level scrolls. So basically, if the right edge of the screen equals the current value of the X dimension in the array, spawn an enemy. Then add 1 to the Y dimension of the array.
My problem comes if the player backtracks through the level and then crosses the point where an enemy spawned previously. I assumed that by adding 1 to the Y dimension, the array was only checking the X dimension of the current Y dimension and ignoring any previous Y dimensions. But it doesn't seem to be doing that.
Can someone please offer some advice on how to use an array this way?
Thanks in advance,
mobichan
Re: ignoring array index values before the current one
I don't know much about arrays, but how about adding a counter/variable and changing the code from:
Right screen edge = Current X of array
- Add 1 to Y of array
to:
Right screen edge = Current X of array
+ Counter <= Y Array
- Add 1 to Y of Array
- Add 1 to Counter
That way, if the player backtracks, the code won't run again until they've got back to where they started backtracking from. I think, anyway. It's 1am in the morning over here, so my pseudo-code is more than likely a bit out :sleep:
Re: ignoring array index values before the current one
I think I understand your logic, but it doesn't seem to be working. :( Anyone else have any suggestions?
Re: ignoring array index values before the current one
Can anyone offer another way to handle this? I need to figure out how to ignore indexes lower than the current one. Or is there a way to delete indexes once they are detected?
Re: ignoring array index values before the current one
Is anyone familiar with using arrays? I'm starting to get desperate here.
Re: ignoring array index values before the current one
I don't quite understand your setup, could you explain it a little better or perhaps upload an example of what you're doing?
Re: ignoring array index values before the current one
I don't have the file in front of me at the moment, but the basic idea is this:
I write out a 2D array from one file that stores enemy data using the X dimension (X1, X2, X3) for (xpos, ypos and enemy type). Then, when I run my game, I am reading the position of a "camera" object that sits on the right edge of the screen. When the camera object's xpos = X1 of the array, I spawn an enemy and increase the Y position of the array by 1. Sorry if my array terminology is off. ^_^'
The Y dimension of my array is used to separate each enemy. After I spawn an enemy, I add 1 to the Y of the array. I thought this meant that the array is only trying to read the data at the current Y position of the array (ignoring all data at previous and future Y positions), but it seems to read through the whole array each frame. I might just need clarification on this. What I want to do is only read the array at its current Y position or at least ignore anything in a previous Y position of the array. The reason is so that if I backtrack through the level, I don't want to respawn an enemy when the camera crosses a previous x position that spawns an enemy.
Does any of this make sense?
Re: ignoring array index values before the current one
I'm quite a novice with arrays myself, but I think Raylax was onto something with his suggestion.
From what I gather you only want the array to be checked once when the camera gets there, but it's constantly checking the whole array. If that is the case, and you are using the Y value of the array (setting it to 1 so it doesn't check that spot again) just set the Y position to 1 after it has been checked, whether or not there is an enemy there.
So ...
If Array Y = 0
check to see if an enemy needs to be spawned (based off of the array's X data)
Set Array Y to 1
Sorry if this isn't helpful, just trying to figure out exactly what it is you need.
Re: ignoring array index values before the current one
Since I am increasing the Y position by 1 after each X(Camera)=X1(Array) becomes true, isn't that supposed to prevent the array from checking against previous Y values? Otherwise, is it pointless for me to be incrementing the Y position at all?
Re: ignoring array index values before the current one
It shouldn't be able to check earlier positions if you increase the Y index, assuming you use Get Value from X and not Get Value from XY. An example would really help to find the problem.
Re: ignoring array index values before the current one
My game has become quite a monster, so I will try to make a simpler version of it this afternoon.
Uploaded the game file and the level layout file (used to export the enemy data):
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=130044&#Post130 044