Screen vs variable initialisation

Hi Forum,

I am struggling with initialization of app that uses multiple screens. I didn't manage to find out if there is any priority on the initialisation. I want to read values from a database into variables on start-up. My logic would say that the app creator should initialise all the variables before running any code e.g. to initialise the screen but in practice it seems not to be reliable.

My current code

initialise global variable to "test"

when screen1.initialise
do set global variable to call tinydb.GetValue tag "variable"

I was expecting that the database entry would overwrite the initialised variable but it seems that sometimes the screen initialises before the variable.

Any ideas? Do I need to be adding a time delay in the screen initialisation?

Please show your relevant blocks

Hi, i have the same issue.

At the start of my app, i begin on the LiveDataRecording screen, for the start of the match, and the TeamAscore variable is initialized and set to zero.

After each Quarter, the user returns to the DataTable screen, to update team players/Quarter number, which are then brought into the LiveDataRecording screen by the TinyDB (this part works fine). The TeamAscore variable is also saved into the TinyDB when exiting the LiveDataRecording screen.

On returning to my LiveDataRecording screen at the start of a new match quarter (Q2, Q3, Q4), my 'TeamAscore' variable is initialised as a zero (as it needs to be at the start of a match, ie Quarter 1), but not then overwritten by the When.Screen.Initialize procedure which is calling the TinyDB that has been created at the end of the previous quarter.

Does the location of the blocks on the screen have any impact on the order of events? I assumed not.

These are the LiveDataRecording screen blocks.

These are the DataTable screen blocks.

You can set the global variable to "test" inside the screen1.initialize block

thanks, that's really helpful!

I'd still like to understand why the TinyDB isnt over-writing the variable, when the screen is initialised?

You could apply a Do It to the section of the Screen.Initialize event that loads from TinyDB the data you want. Maybe it was never stored, or got erased?

Thanks, i have a textbox on the DataTable screen that i use for debugging, and that will correctly reported the TeamAscore from the TinyDB. This indicates that the TinyDB has stored the variable, but it is the initialisation sequence on the LiveDataRecording screen that is the issue?

Empty math blocks are an error.

They should be 0.