Page 1 of 1

RemoveItem with Brush

Posted: Mon Apr 02, 2018 11:54 pm
by sinisrus
Hello,

If I remove an entry containing a brush the brush is not released
It is necessary to use freebrush ()?

Code: Select all

a={}
a[0]=CreateBrush(NIL,10,10,#BLUE)
a[1]=CreateBrush(NIL,10,10,#GREEN) 

RemoveItem(a,1)
t, c = GetObjects(#BRUSH) DebugPrint(c)
Thank you

Re: RemoveItem with Brush

Posted: Tue Apr 03, 2018 11:56 am
by airsoftsoftwair
Yes, of course you need FreeBrush(). RemoveItem() just removes a table item, it doesn't care about what that table item actually is.

Re: RemoveItem with Brush

Posted: Wed Apr 04, 2018 10:20 am
by sinisrus
It is strange not to delete the contents of the item, the brush is no longer usable anyway ?!?

Code: Select all

a[1] = CreateBrush (NIL, 10.10, # GREEN)
RemoveItem (a, 1)

Re: RemoveItem with Brush

Posted: Wed Apr 04, 2018 5:19 pm
by jPV
Only the brush ID is stored to the table/variable, not the actual brush, and they are handled just as any other variable. How could Hollywood guess if you want to remove the brush or not when you remove a table item? Hollywood doesn't know if you've made, for example, b=a[1] earlier :)

Re: RemoveItem with Brush

Posted: Wed Apr 04, 2018 5:29 pm
by sinisrus
@JPV

Ok i understand well
but how do I call the brush if I have not A [1] ?

Re: RemoveItem with Brush

Posted: Wed Apr 04, 2018 5:38 pm
by jPV
sinisrus wrote:but how do I call the brush if I have not A [1] ?

Code: Select all

a={}
a[0]=CreateBrush(NIL,10,10,#BLUE)
a[1]=CreateBrush(NIL,10,10,#GREEN) 
RemoveItem(a,1)
t, c = GetObjects(#BRUSH) DebugPrint(c)
DisplayBrush(t[1],0,0)

Re: RemoveItem with Brush

Posted: Wed Apr 04, 2018 8:15 pm
by Bugala
"How to call a brush?"

Idea with Brushes is that each brush has its own ID.

You could make a new brush:

Code: Select all

CreateBrush(1,10,10,#BLUE)
And now this would be Brush number 1, in which case you could use:

Code: Select all

DisplayBrush(1,0,0)

You can also have more brushes, say:

Code: Select all

CreateBrush(1,10,10,#BLUE)
CreateBrush(2,10,10,#GREEN)
CreateBrush(3, 10,10,#BLACK)
And now you can use for example:

Code: Select all

DisplayBrush(2,0,0)
And it would now be displaying Brush number 2, which is #GREEN

Notice if you after having put those three brushes do following:

Code: Select all

CreateBrush(1,10,10,#BLUE)
CreateBrush(2,10,10,#GREEN)
CreateBrush(3, 10,10,#BLACK)

CreateBrush(1, 10,10,#WHITE)

DisplayBrush(1, 0, 0)
That would now be displaying a #WHITE brush.
This is because when you made another CreateBrush with ID 1, it replaced the old Brush ID 1, with this new brush. Hence the old Brush ID 1 (#BLUE) doesnt exist anymore.


Now, in your code you have been instead of using Direct numbers like 1, 2, 3, you have instead used NIL as the ID.
This NIL is a special case when creating Brushes (used by some other commands as well).
Idea is, that instead of you giving the brush a direct ID number, NIL is going to be giving you the first available number.

Hence for example using:

Code: Select all

CreateBrush(NIL,10,10,#BLUE)
CreateBrush(NIL,10,10,#GREEN)
CreateBrush(NIL, 10,10,#BLACK)
CreateBrush(NIL, 10,10,#WHITE)
Could in practice result in you having Brush ID 1 containing #BLUE, ID 2 containing #GREEN... But you cant know that for sure. It depends what you created before.
For example, if you already have created Brush ID 1, 2 and 3, then these four would be getting IDs 4, 5, 6, and 7.

regardless what ID they actually get, idea is not to guess them, but to store them somewhere, hence you could for example have:

Code: Select all

BlueCube = CreateBrush(NIL,10,10,#BLUE)
GreenCube = CreateBrush(NIL,10,10,#GREEN)
BlackCube = CreateBrush(NIL, 10,10,#BLACK)
WhiteCube = CreateBrush(NIL, 10,10,#WHITE)
Now since you stored them in a variable, you dont need to know their actual ID numbers anymore. You dont need to worry if BlueCube in practice is 1, 2, 3 or whatever number. All you need to know is that whatever that number is, it is stored in variable BlueCube.

And hence you can simply use:

Code: Select all

DisplayBrush(BlueCube, 0, 0)
and regardless what ever BlueCubes ID is, it is now being displayed. Just like you would be using "DisplayBrush(1, 0, 0)" (supposing BlueCube ID would be 1).


So what you effectively was doing with your table, was that you were storing these IDs in a table.

As example:

Code: Select all

MyBrushes = {}
MyBrushes[1] = BlueCube
MyBrushes[2] = GreenCube
However, as you were storing the actual ID directly to the table, in way of:

Code: Select all

MyBruhses = {}
MyBrushes[1] = CreateBrush(NIL, 10,10, #BLUE)
That table was therefore only place containing the actual ID number, and hence if you destroyed that table, or table item, there was no reliable way of getting Brushes ID anymore after that.

You could compare the situation so that you have 100s of discs, each containing only one number in them, 1, 2, 3...
In addition to this you have a notebook which reads: "My movies in alphabetical order: Ghostbusters- 23, Indiana Jones and the Raiders of the Lost ark- 97, Karate Kid- 3..."

Now if you lose your notebook. Then your Discs would still contain those movies, you just wouldnt know what each disc contains anymore, since you would only have the numbers on those discs, but you wouldnt know to what movie each number refers to. This situation is a bit similar.

Hope this explanation made you understand the situation.

Re: RemoveItem with Brush

Posted: Thu Apr 05, 2018 5:58 pm
by sinisrus
Thank you :-)