Page 1 of 1
Any way to have Returned Local used inside the SetInterval declaration?
Posted: Sat May 17, 2025 9:07 pm
by Bugala
I can use Local IntID to do something like this:
Code: Select all
Local IntID = SetInterval(Nil, Function()
EndFunction, 10)
InstallEventHandler({OnMouseUp = Function()
ClearInterval(IntID)
EndFunction})
But what if I want to use that Local IntID already inside the SetInterval, as in:
Code: Select all
Local IntID = SetInterval(Nil, Function()
If X=True then ClearInterval(IntID)
EndFunction, 10)
is there any way to get it done this way, as in, without dedicating a variable to it, since I can of course do it without Local, for example:
Code: Select all
IntID = SetInterval(Nil, Function()
If X=True then ClearInterval(IntID)
EndFunction, 10)
But then I need to take care that I am not using that Variable name anywhere else. Hence I would like to just have Local variable, so I don't need to worry about conflicting it later accidentally.
Re: Any way to have Returned Local used inside the SetInterval declaration?
Posted: Mon May 19, 2025 7:49 am
by jPV
This should work.
Code: Select all
Local IntID = SetInterval(Nil, Function(msg)
If X=True Then ClearInterval(msg.ID)
EndFunction, 10)
Re: Any way to have Returned Local used inside the SetInterval declaration?
Posted: Mon May 19, 2025 8:39 am
by jPV
And if you only handle the interval inside its calling function, you don't need to store the ID at all.
This would do then:
Code: Select all
SetInterval(Nil, Function(msg)
If X=True Then ClearInterval(msg.ID)
EndFunction, 10)
Re: Any way to have Returned Local used inside the SetInterval declaration?
Posted: Mon May 19, 2025 8:49 am
by Bugala
Yes indeed, forgot that these things send these msg tables with info about them. Thanks a lot JPV, Now I can do it fully with locals.
Point being that I do need the local in addition for the OnMouseUp EventHandler, but in addition can use the msg.id to handle the SetInterval one, without needing to dedicate global variable to it.
Good I asked, for I almost didn't since I thought there would be no way, but forgot the msg.ID part.
Point in this is that I am having a windows move/copy file kind of system, where when having mouse down it starts an interval, making it possible to select multiple files by going over the files with mouse, but in addition, if I move the mouse out of window, then it changes to moving the files (to other windows), which means that it needs to stop that interval it is currently running, which takes care of mulitselection and checking if mouse moves out the window, but in addition, there is also OnMouseUp event, which also will end the same interval to stop the multiselection. Hence I need the ID both inside the SetInterval, and then outside on that InstallEventHandler, but I can use Msg.ID for the SetInterval, and Local for the InstallEventHandler. Problem solved.
Thanks a lot!