Why is this not working? (possibly bug)

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1400
Joined: Sun Feb 14, 2010 7:11 pm

Why is this not working? (possibly bug)

Post by Bugala »

Code: Select all

@SCREEN {Mode = "FakeFullScreen"}
@DISPLAY {Width = 1920, Height = 1080, Borderless = True, ScaleMode = #SCALEMODE_AUTO, FitScale=True}

EnableLayers


CreateBrush(1, 50, 50, $CCCC55)
InsertLayer(1, #BRUSH, 1, 885, 650)	
InsertLayer(2, #BRUSH, 1, 935, 650)
InsertLayer(3, #BRUSH, 1, 985, 650)	
InsertLayer(4, #BRUSH, 1, 935, 600)
InsertLayer(5, #BRUSH, 1, 935, 450)	

For n=1 To 5
	DebugPrint(n)
	RemoveLayer(n)
Next
When i try to run, it fails at point it tries to remove layer number 4. Why?

Is this a bug or is it supposed to work this way?
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Why is this not working? (possibly bug)

Post by Allanon »

If you have a look at the layer introduction you can see that the layer id is dinamically changed when you use the RemoveLayer() function, see below:

layer id 1 -> obj a
layer id 2 -> obj b
layer id 3 -> obj c

if you remove layer 2 with RemoveLayer you will have
layer id 1 -> obj a
layer id 2 -> obj c

So, if you want that your code will work you have at least use the for .. next inverted with:

Code: Select all

For n=5 To 1 step -1
   DebugPrint(n)
   RemoveLayer(n)
Next
Or alternatively, you should use layer names to be sure that you are deleting exactly want you want.

P.S.: code not tried
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
Bugala
Posts: 1400
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why is this not working? (possibly bug)

Post by Bugala »

Ah, okay, thanks Allan!

That explains it.

I normally use layernames and this was just exceptional that i decided it would be easier to use layerids instead so hence it didnt come to my mind that it would keep reordering the queue.
Post Reply