#I have two loops for 2 opposite
1 messages · Page 1 of 1 (latest)
A little bit. nested for loops are often prone to problems.
right and like I was saying originally I was doing this in separate loops but someone told me I should go x positive, then x negative, so on till both loops were over because: I'm trying to extend either loop depending
I'm imagine that you're writing some sort of an island generator code? Just trying to see it execute.
well the generator itself is working fine I'm actually trying to write an explosive that bases it's detonation on surrounding cells
I think you need to avoid using "Break" and use "Continue" instead.
When you call "Break" it exits the loop.
does the nested continue though?
You wanted the loop to continue because you updated the new range value.
Take this for example
for (int posX = cell.Position.x; posX < cell.Position.x + RemainingxNeg; posX++)
When you called the line before "break" you updated the new remaining value.
But you broke out of the loop by calling break.
You need to let the loop continues until it reaches the end condition.
still the same result with continue in place of break so I think in this particular case it's something else
breaking out of the loop was intended
*Just as long as the nested can continue
RemainingxPos = MaxExplodeCells + (Mathf.Abs(cell.Position.x + MaxExplodeCells) - Mathf.Abs(posX));
Explain to me what this is suppose to do.
so for example I have the explosive sitting in an empty field, it can go 3 tiles in the positive direction and the negative from where it's sitting..
now instead lets say the bomb is sitting next to a wall (the wall is sitting on the negative axis)
I want the Positive axis to take those 3 cells meant for the negative, that was halted because of the wall and extend so now, opposite of the wall is 6 tiles instead of 3
that line is supposed to check how far from the intended length was reached
RemainingxPos is to add to the opposite loop's length
hopefully that makes sense
I think this for loop is confusing. You want your explosion radius to go all direction. You'd have to write another set of loops to start from the origin to the opposite direction. It almost sounds like a spherecast... Sorta.
it's taking inspiration from Bomberman so I don't need a full on spherecast
a collection of cell-specific spherecasts rather
I agree- it is confusing 🤣
(in case you haven't played bomberman, a bomb can go off like a Castle moves in chess
Watching Bomberman atm...
non-diagonal essentially, it's an older cell-based game
Then a raycast would suffice?
If you need to do this procedurally with this two loops
I'm spherecasting in the end, from a collection of points.. it could be a raycast or spherecast regardless I need to know the cells which are effected