#Will my for loop keep running after the catch block catches an exception

1 messages · Page 1 of 1 (latest)

junior sedge
#

aaa

fluid shellBOT
#

This post has been reserved for your question.

Hey @junior sedge! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

junior sedge
static epoch
#

the try/catch is executed once for every iteration of the loop, it has no bearing on the iteration of the loop

junior sedge
#

inside catch right

#

cuz i want to stop it from looping if it catches an error

#

catch an error - > delete placed tiles -> stop the looping

static epoch
#

put the for in the try then

junior sedge
#

that will still k++ ?

static epoch
#

why delete placed tiles? you shouldntve placed them if it's an invalid state

junior sedge
static epoch
#

why not just check all of them, and only if they all pass, place all of them

#

why worry about cleanup when you can just not create a dirty state to begin with

junior sedge
#

im placing a line of tiles

static epoch
#

no, not really

junior sedge
#

the first 3 could respect the rules

#

but the last one no

#

it already doesnt place them if the rules are easy to detect

static epoch
#

yeah so only place them after you've checked all the tiles

#

so just.. do that here

#

having a consistent system will make it much easier to work with

#

could use streams

junior sedge
#

The basic checks like: 2 tiles in same line identical, 2 tiles in same line have different shape AND color, tile in line place already occupied by another tile, line of tiles placed somewhere where there isnt any other tile near. These basic checks dont place the tiles they just throw exception.

#

The hard check is the one where im checking in the grid in the line they will be placed if there is another tile touching with different color and shape

#

and for that i must place the tiles, so I can iterate through the whole line

#

otherwise around it its null

#

and it throws an exception

static epoch
#

you really don't

#

you can just check each tile in the sequence of tiles that are about to be placed there

static epoch
#

the obvious solution has a trivial issue, and your reaction is to discard it and mix in a completely different way of doing things?

junior sedge
#

for example

#

this placement here is incorrect

#

the way im doing things right now

#

it places the blue square up there because that one is valid

#

and then the circle it checks for it

static epoch
#

i have no idea what the check actually is because you're so vague about it, but i assure you, it's much easier than fumbling with partial/dirty state

junior sedge
static epoch
#

then maybe try to be more specific

junior sedge
#

sec

static epoch
#

either way, you're going down the wrong path, just continue along the path you've been going down before

#

nope don't want to hear it

junior sedge
#

anyways

#

this placement here is valid

#

even tho 2 identical tiles are on the same line in the grid

#

because they arent touching each other nor touching another line with the same tile

#

so i must check if there is a null everytime im checking, because when i find the null it means im done with the line and all gucci

#

except when trying for a line if i dont actually place the tiles itll detect nulls

#

because the path they got placed in is not there

#

and its important to place them because the tile at position 5 could perfectly be touching another line

#

so its not enough by just checking the line they got attached to

static epoch
# junior sedge don't ask me to be specific then

aight ok let me be clear.
be more specific next time
imma just be blunt, you need to figure out how to ask better questions, give enough info to actually be helped
but this help thread doesn't need that, there's not really anything more to add. you can implement the checks without a partial state just fine, whatever they may be

static epoch
junior sedge
#

but thats more work than just placing and checking

#

and if invalid remove all

static epoch
#

it isn't

junior sedge
#

innocent until proven guilty

static epoch
#

you're just being stubborn now

junior sedge
#

no I actually believe it is more work

#

or maybe it isnt for the machine

#

for the machine its maybe less work

#

but for the human brain im carrying it is more work

#

but then again the point is to make it less work for the machine i guess

static epoch
#

ok but

  1. it isn't.
  2. this is conflicting with your existing design. this is how spaghetti code is born.
  3. this is much less safe, just by nature of partial states.
  4. it's more bug and error prone.

it's less work to implement because it reuses other parts of your design, and it saves you work fixing the damn thing

#

but sure go make your spaghetti code if you so believe it's less work

junior sedge
#

because by doing this "spaghetti code" im allowing myself to reuse the code that checks for one tile

static epoch
#

you can reuse code here too, yknow

static epoch
#

im done here

junior sedge
#

I wrote much more lines but hey

#

if its better to write 10 extra lines than to have spaghetti code

#

why not