#I have two loops for 2 opposite

1 messages · Page 1 of 1 (latest)

noble badge
#

Can we have a conversation here, I don't want to lose this info.

blazing spear
#

Yep sounds good

#

does it make sense what I'm going for?

#

feel like I'm close

noble badge
#

A little bit. nested for loops are often prone to problems.

blazing spear
#

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

noble badge
#

I'm imagine that you're writing some sort of an island generator code? Just trying to see it execute.

blazing spear
#

well the generator itself is working fine I'm actually trying to write an explosive that bases it's detonation on surrounding cells

noble badge
#

I think you need to avoid using "Break" and use "Continue" instead.

#

When you call "Break" it exits the loop.

blazing spear
#

does the nested continue though?

noble badge
#

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.

blazing spear
#

breaking out of the loop was intended

#

*Just as long as the nested can continue

noble badge
#
RemainingxPos = MaxExplodeCells + (Mathf.Abs(cell.Position.x + MaxExplodeCells) - Mathf.Abs(posX));
#

Explain to me what this is suppose to do.

blazing spear
#

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

blazing spear
#

RemainingxPos is to add to the opposite loop's length

#

hopefully that makes sense

noble badge
#

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.

blazing spear
#

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

noble badge
#

Watching Bomberman atm...

blazing spear
#

non-diagonal essentially, it's an older cell-based game

noble badge
#

Then a raycast would suffice?

#

If you need to do this procedurally with this two loops

blazing spear
#

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

noble badge
#

You'd probably invest into using a circle circumference for checking.

#

Your x being Mathf.Sin, your y being Mathf.Cos

#

And every 4 modulus, you'd advance the radius.

blazing spear
#

ehh well see I have the positions I want that's not the issue it's just modifying the loops that seems to be the issue

#

the loop length I should say