menuPujie Watch Faces logoPujie Watch Faces logo
Automatic translation by Google Translate
Restore translation

Automation / Scripting

A collection of frequently asked questions related to the automation functionality.

Content
What needs to be changed for the tap action update for global variables?

Since version 6.1 the global variables keep state. This means that variables inside the global object are only initialized once. As a result, some behavior has changed.

For instance, before, you could write:

[global].variable = 10;
[global].bat = [bat_p];

and then in your layers use [global].bat, which would always have the latest value of [bat_p] because the global script was executed every frame. Also [global].variable would always be 10.

Now inside a tap automation, you can do things like:

[global].variable = 15;

This would change the state of the [global] object (the value of the variable becomes 15). If the global script was executed again, the [global].variable would be set back to 10. We don't want this anymore because we want it to keep state!

When the [global] script is only executed once, you can change variables from other scripts and it will keep state! Great, that is what we want. But.. this will also mean that [global].bat = [bat_p] is also only executed once, so [global].bat will only have the battery level at the moment it was initialized. Thus, those kinds of statements may not work as intended anymore.

What you should do now is:

[global].variable = 10;
[global].bat = function() {
return [bat_p];
}

and then use [global].bat() as a function in your layers, this will return the latest value of [bat_p].