How to detect a change in a global variable ?
scott at elementarysoftware.com
scott at elementarysoftware.com
Sat Jul 26 04:59:08 EDT 2025
The way that the loop is written would make it blocking. If you wanted the loop to start running and then stop after the mouseUp happens I think you would need to add a "wait x millisec with messages”
Fo example:
global myVar
on elsoTester
put 0 into myVar
-- some code
repeat until myVar > 0
-- set the thumbPosition of scrollBar "ProgressBar" to (the thumbPosition of scrollBar "ProgressBar" + 5) -- testing
wait 500 millisec with messages
end repeat
-- some code
answer "Finished"
end elsoTester
Depending on what you are doing, another method would be to use a "send it time" mechanism where the handler keeps calling itself until myVar > 0
For example:
local sFlag
global myVar
command elsoTester
if sFlag is empty then
put 0 into myVar
-- some code
end if
repeat until myVar > 0
-- set the thumbPosition of scrollBar "ProgressBar" to (the thumbPosition of scrollBar "ProgressBar" + 5) -- testing
put “waiting” into sFlag
send elsoTester to me in 500 millisec
exit elsoTester
end repeat
answer “Finished"
end elsoTester
To be thorough you might also might want to empty the message queue of any other elsoTester messages before sending in time or add a timer which will eventually time out if myVar doesn’t exceed 0 after a set time.
--
Scott Morrow
Elementary Software
(Now with 20% less chalk dust!)
web https://elementarysoftware.com/
email scott at elementarysoftware.com
booth 1-360-734-4701
------------------------------------------------------
> On Jul 26, 2025, at 12:44 AM, jbv via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Hi list,
>
> Let's say I have a portion of a script like this :
>
> global myVar
> put 0 into myVar
> -- some code
> repeat until myVar > 0
> end repeat
> -- some code
>
> and the content of global myVar being changed
> in a handler of another control :
>
> on mouseUp
> global myVar
> put 1 into myVar
> end mouseUp
>
> I know this is not very elegant, but my question is :
> can the change in myVar be detected in a loop like
> above ?
> I made some tests and it doesn't seem to work...
>
> Thank you in advance.
> jbv
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list