In what order Local X = makebutton(NIL... happens?

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

In what order Local X = makebutton(NIL... happens?

Post by Bugala »

I have this piece of code that is not working:

Code: Select all

{OnMouseDown = Function() 
			Local DragBarIntervalID = SetInterval(Nil, Function()
					If IsLeftMouse() = False Then ClearInterval(DragBarIntervalID)
I suppose it doesn't work because Local DragBarIntervalID memory address is not reserved until the creation part is done first.

But I am wondering if there would be some way to get this done this way, without needing to use some outside Variable like Dragbar.IntervalID, or dedicated number.

Therefore, what is the order in which memory reservation for variables happen in this case?
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: In what order Local X = makebutton(NIL... happens?

Post by Bugala »

Actually, already figured it out, but here if someone else wants to do this way too:

Code: Select all

{OnMouseDown = Function() 
			Local DragBarIntervalID
			DragBarIntervalID = SetInterval(Nil, Function()
					If IsLeftMouse() = False Then ClearInterval(DragBarIntervalID)
By otherwords, Need to use "Local DragBarIntervalID" to create the Variable and memory space be reserved.

This way, when creation part is done, it will be referencing inside the ClearInterval(DragBarIntervalID), which value is actually only decided at point when it returns from the creation part.

That however isn't a problem, since the value in the memory address (=variable) is not being asked until it is actually executed in the program, after the creation has already happened.
Post Reply