Fun Share: Global Function Hack

As a contribution towards workarounds or hacks to get things done, I present this demo of a Global Function Hack.

https://x.thunkable.com/copy/73d9acde23febf02fcebd3efb8d91d53
The project has 2 screens. I have the function in screen 1 but I am calling it from screen 2. You will see that every time you click the button in screen 2, the function in screen 1 is executed and the result is shown in the label in screen 2.

Happy Thunking!

3 Likes

This is great!

Here is another example using a similar method from @actech

https://x.thunkable.com/projects/5d70f93f8a62b4079eedaff2/d75829bd-a6b5-481b-9a3a-59315a3cdb10/blocks

2 Likes

I looked around quickly in the screen captioned scrGlobalFunctions but could not figure out how it is implemented. I may need to look again, maybe it is done in a better way.

I can tell you that it would take me a little while to understand the full implementation too! I’ve seen it work well, though! :slight_smile:

Yours is far. more straightforward

1 Like

Say what? Timers function on non-active screens?

2 Likes

It seems so. Even though the screen is not the active one, the timer Fires block runs once you set the timer enable to true.

I also found out that if you keep all timer options in the setup screen disabled then it will only run once which is what I was looking for. At first I was keeping an extra block of code in the function to turn the timer enable option to false but then I realized I do not need it.

1 Like

Hi Thunkers!

This gave me an ideia, what if we could update the label in screen 2 on resultHandler change event?! I tried it but with no sucess .The event is not fired when resultHandler changes inside the timer :frowning:

1 Like

If this was possible we wouldn’t have gone all this rounded path to get it done.

The first attempt I did was with the when initializes or changes block.

This block only detects changes within the same screen.

1 Like

Hi all,

Just to extend the demo of Global Function further than just adding two variables, I created another function in the first screen. This time the function executes Web API and saves the response to a variable.

I also created a third screen that runs this function and then waits for the variable to get updated and show the response of the Web API located in screen 1 in the labels of screen 3.

Another enhancement in this demo is in the timer component which now has a conditional parameter to decide which function to execute making use of one single timer to run more than on function as inquired by @paulovaz72

Hope this makes the demo more interesting.

2 Likes