Global "do if"?

Hello all.

I am new here, but fairly active in Thunkable. was wondering if it is possible to have some sort of function always watching a variable, and if that variable changes, you can trigger an event.

For example I want to watch a variable, and if that variable matches “something” (which could be set from a variety of different places) can an event handler see that, and then trigger a new action. (maybe a notify or something)

The principal is to have a “global watch”, so I don’t have to build the checkin every time. Now I know I can create a function/procedure, and call it every time, however I was hoping there was a better global approach.

I hope I am making sense. Any insights?

1 Like
Clock1.TimerInterval = 0;
Clock1.TimerEnabled = true;
When Clock1.Timer {
    if variable == [required condition] {
        call function f();
        Clock1.TimerEnabled = false;
    }
}

function f() {
    //do stuff
    Clock1.TimerEnabled = true;
}
2 Likes

THANK YOU!! I am so happy to get a detailed response. I think I did something wrong. Would you be so kind as to check my translation.

I have converted what you put into blocks. I am trying to workaround a bug I have with Cloudinary. This is how I translated your great code. Things are not working. Thoughts?

Initialize

Block 1

Block 2

Put the “set Clock1.TimerEnabled = false;” inside the “then” portion of the “if” block in your Clock1.Timer event.

Notice how the Timer is disabled inside the curly braces of the if. Also, you need to disable timer, carry out the function and then reenable the timer.

In your particular case, you aren’t carrying out a large function that could hog the timer (the disabling and reenabling is a foolproofing method).

I have these suggestions for you:

  1. Do not use a “variable == true” setup; just plug the variable directly into the if.
  2. Do not disable the timer.
  3. Set the TimerInterval and TimerEnabled in the Design panel Property Inspector itself, instead of programmatically setting it on Screen.Initialize.
3 Likes

I got this to work with a few tweaks and very well. Thank you for that!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.