[ SOLVED ] Storage doesn't work after change Scene

I make a simple project with only 2 scenes. Scene 1 as default start scene.
Project file : https://file.io/qpOBkhAVmvxg

Scene 1
Screenshot from 2024-09-20 09-05-45

Scene 2
Screenshot from 2024-09-20 09-06-07

Variable (Global)

Everytime I click Generate, it will create a text with id (1,2,3,4,5…) and save it ( id and Y position ). If I close the app and then open again, the app will reproduce the saved texts ( id and Y position ) like this :


.
.
.
But if from Scene 1 I go to Scene 2, then go back to Scene 1, the app can’t reproduce the saved texts again. The id and Y position are different. :



.
.
.
But, if I close the app and then open again, the the app reproduce saved text again. Or, If I open from Scene 2 and Go to Scene 1, the the app also reproduce saved text again :

.
.
.
Why If I start from Scene 1, then Go to Scene 2 and go back to Scene 1, the app can’t reproduce the saved texts?

It’s because variable n is a global variable and doesn’t lose it’s value between scene changes, but does get reset when the app is started.

When the app starts, n is 0. Each time you generate a new lis object, n increments by 1. In scene 2, n is still the number of lis objects in scene 1.

Returning to scene 1 keeps n unchanged. During the nS repetitions event, n increments, and the lis object’s ID is updated to n. Since this value doesn’t yet exist in storage, the Y position is set 100 pixels below the previous lis, and its text remains unchanged.

1 Like

Thank you very much for your help. So I need to reset n (n=0) at beginning and it’s solve the problem.

1 Like