Using Global Variables

Hello,
I just started using a basic display from Nextion.
Got to view some variables from esp and also setting some.
i was asking mcu to send me vars all the time i was changing pages and updating just that pages vars (was quite slow and useless asking all the time vars), later i thought to get a page called variables where storing all the variables as global and asking mcu to update it.
So just at the beginning I send a printh to the controller to update my vars.
After that i wait a second and i change page, in the preiniatilize event of that page i set some number or text to get its val or txt from global variables.
Ok fine it’s work the first time, but later when i’m gonna recall that page it cannot get variables from global like if it doesn’t store it…
I just tried to use a button to getting again vars from page where are stored as global and seems like they are empty…

My intention is to store variables and getting them between pages, later from controller updating them every n seconds or also asking to update it from nextion if something is wrong.
At the moment i’m asking to refresh vars from esp all the time i change page but it’s worst than before because i have to ask for 30 vars versus the 10 that i need.

btw i have basic version no rtc or eeprom.

Thanks a lot, have a nice day.

With the newest 1.6 editor version, you can declare as many global variables as you have memory available, using the program.s file. The “classic” system variables, sys0 to sys2, are declared there for compatibility with previous versions, just follow that example.
You can load from these in the page load event, you can update these asynchronously from the MCU when needed, this should solve your problem.

Thanks i saw,
By the way i have also some String var i should divide some var in a page and some in program.s.
Are there problem to store String with 20+ chracters because seems most of the time it doesnt store it or it get the precedent value.
I find out that i have to run the page in the beginning to make it store Vars.

Thanks

Can you declare string variables in the Programm.s folder? If yes what is the syntax?
Thank you

Actually, only numeric (integer) global variables can be declared in program.s

To use global strings, you’ll need to place a variable component on a page, set its property from number (default) to text and make its scope global. Then, it will be accessible from all pages. It’s just important to let the compiler always know where this global txt ist stored by full page.component addressing. Example btn0.txt=page0.va2.txt