Make data available to next opening window after current window closes
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Make data available to next opening window after current window closes
Hi,
I have a program I'm working on that has multiple screens(windows), but only one open at a time mostly. Once one window closes then next window opens. How do you make the data from current window available to the next window without losing the data when current window closes? I tried using global linked lists, but only could get sort of to the next window and I need the data to be available to all windows. At some point it started telling me that the list didn't exist. Each window code is in it's own include file. I also have tried to use PureVision for this, but I'm not sure how to go about doing it that way because the actual game play doesn't start until the 7th window opens. The first 6 are more less game setup windows. stuff like player names and game type etc, etc.
I have not tried global arrays yet because I do not like that you can't insert or remove any element from anywhere but the end. To me that limits the ability to manipulate arrays to your needs. I have seen an example using pointers to manipulate arrays, but pointers confuse me especially if there are a lot of pointers in a program. There is a simple way to manipulate arrays, but it would get very very tedious to do it that way and it wouldn't be effective. Plus there would be a lot of coding to change elements as needed and be very messy.
Am I going to have to have a window open at all times even if it is hidden to hold the data in memory for each active window as it opens, or what?
I have a program I'm working on that has multiple screens(windows), but only one open at a time mostly. Once one window closes then next window opens. How do you make the data from current window available to the next window without losing the data when current window closes? I tried using global linked lists, but only could get sort of to the next window and I need the data to be available to all windows. At some point it started telling me that the list didn't exist. Each window code is in it's own include file. I also have tried to use PureVision for this, but I'm not sure how to go about doing it that way because the actual game play doesn't start until the 7th window opens. The first 6 are more less game setup windows. stuff like player names and game type etc, etc.
I have not tried global arrays yet because I do not like that you can't insert or remove any element from anywhere but the end. To me that limits the ability to manipulate arrays to your needs. I have seen an example using pointers to manipulate arrays, but pointers confuse me especially if there are a lot of pointers in a program. There is a simple way to manipulate arrays, but it would get very very tedious to do it that way and it wouldn't be effective. Plus there would be a lot of coding to change elements as needed and be very messy.
Am I going to have to have a window open at all times even if it is hidden to hold the data in memory for each active window as it opens, or what?
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
Re: Make data available to next opening window after current window closes
You can choose many different ways to store your data. A physical database, global structured arrays/lists/maps.
Just update data on window close event or something more frequent.
Just update data on window close event or something more frequent.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
So should I save the data to a file of some sort e.g. database, .txt or .dat and reload the data as needed for each window?skywalk wrote: Mon Apr 29, 2024 1:59 am You can choose many different ways to store your data. A physical database, global structured arrays/lists/maps.
Just update data on window close event or something more frequent.
Last edited by Distorted Pixel on Mon Apr 29, 2024 4:02 pm, edited 1 time in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
Re: Make data available to next opening window after current window closes
You wrote, that each window code is inside its own include file,so you have one App with multiple windows? Or is each window opened in its own process?
Normally, a linked list (or array, map, variable and so on) is not tied to a window and shouldn't get erased when simply closing it.
Normally, a linked list (or array, map, variable and so on) is not tied to a window and shouldn't get erased when simply closing it.
- Fangbeast
- PureBasic Protozoa

- Posts: 4792
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Make data available to next opening window after current window closes
Linked lists can be global so everyone can see it or just local to the procedure. Just say
Global Newlist Listname.Datatype() to create a simple list or
Global Newlist Listname.Structurename()
to base it on a structured list with all sorts of data types.()
Global Newlist Listname.Datatype() to create a simple list or
Global Newlist Listname.Structurename()
to base it on a structured list with all sorts of data types.()
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Make data available to next opening window after current window closes
You can also create a database in memory using SQLite without having to write it to a file by using OpenDatabase(DBase, ":memory:", "", "").Distorted Pixel wrote: Mon Apr 29, 2024 3:59 amSo should I save the data to a file of some sort e.g. database, .txt or .dat and reload the data as needed for each window?skywalk wrote: Mon Apr 29, 2024 1:59 am You can choose many different ways to store your data. A physical database, global structured arrays/lists/maps.
Just update data on window close event or something more frequent.
Re: Make data available to next opening window after current window closes
A global list should do what you want. If it isn't working then there is a problem with your code somewhere.
If your code is not working with a linked list then just changing to an array isn't going to help with anything. For the purposes of scope the two are equivalent.
I'm repeating myself here but windows are not scopes for the purposes of variable declarations. Variables do not 'live' in windows. They 'live' in memory somewhere.Distorted Pixel wrote: Mon Apr 29, 2024 12:14 am Am I going to have to have a window open at all times even if it is hidden to hold the data in memory for each active window as it opens, or what?
There is a positional logic problem which can cause this fault, look at this code:Distorted Pixel wrote: Mon Apr 29, 2024 12:14 am At some point it started telling me that the list didn't exist.
Code: Select all
; ...
; In hypothetical IncludeFile "WindowA"
; ...
Global NewList List1.i()
Procedure A()
Debug ListSize(List1())
Debug ListSize(List2())
EndProcedure
; ...
; In hypothetical IncludeFile "WindowB"
; ...
Global NewList List2.i()
Procedure B()
Debug ListSize(List1())
Debug ListSize(List2())
EndProcedure
; ...
; In a main file
; IncludeFile "WindowA"
; IncludeFile "WindowB"
A()
B()PureBasic is a single pass compiler, it can't go back and 'fill in the blanks' of unresolved references.
I'm guessing that you have some kind of problem along these lines. The solution is to ensure all the globals are declared before all the procedures which reference them:
Code: Select all
; In a main file
; ...
Global NewList List1.i()
Global NewList List2.i()
; ...
; In hypothetical IncludeFile "WindowA"
; ...
Procedure A()
Debug ListSize(List1())
Debug ListSize(List2())
EndProcedure
; ...
; In hypothetical IncludeFile "WindowB"
; ...
Procedure B()
Debug ListSize(List1())
Debug ListSize(List2())
EndProcedure
; IncludeFile "WindowA"
; IncludeFile "WindowB"
; in a main file after the window files:
A()
B()- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
In one project I am using PureVision for creating the user interface easier.Mr.L wrote: Mon Apr 29, 2024 6:45 am You wrote, that each window code is inside its own include file,so you have one App with multiple windows? Or is each window opened in its own process?
Normally, a linked list (or array, map, variable and so on) is not tied to a window and shouldn't get erased when simply closing it.
Yes, it is one app with multiple windows. I would like to have one game loop and I will have to get back to that. I have tried having each window have it's own loop, but not only is that sloppy coding, but when it came to adding elements to the global linked list, it claimed that the linked list did not exist when the second window was open after you select how many players and then click the "Ok" button.
My goal is to have one game loop. The game will have around 20 - 80 different screens(windows) with the first 6 as game setup windows and will never be accessed again unless a new game is started. Technically 7 screens(windows) because I want to splash screen to show first and then the 6 setup windows.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
I will probably have to be the structured way because this game is going to have a massive amount of data to keep track of.Fangbeast wrote: Mon Apr 29, 2024 12:08 pm Linked lists can be global so everyone can see it or just local to the procedure. Just say
Global Newlist Listname.Datatype() to create a simple list or
Global Newlist Listname.Structurename()
to base it on a structured list with all sorts of data types.()
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
Yes, I was planning on using SQlite for data saving and tracking. I figured that it would be ther best way to track data for this game because there will be a massive amount of data to save and track as things change throughout the course of the gameDemivec wrote: Mon Apr 29, 2024 9:06 pmYou can also create a database in memory using SQLite without having to write it to a file by using OpenDatabase(DBase, ":memory:", "", "").Distorted Pixel wrote: Mon Apr 29, 2024 3:59 amSo should I save the data to a file of some sort e.g. database, .txt or .dat and reload the data as needed for each window?skywalk wrote: Mon Apr 29, 2024 1:59 am You can choose many different ways to store your data. A physical database, global structured arrays/lists/maps.
Just update data on window close event or something more frequent.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
I understand your example, but I even tried to create the global linked in the main code file after the XIncludeFile with a hidden window that never closed just to see if it would work to no avail.spikey says:
In this example Procedure A won't compile even though both List1 and List2 are declared global. List2 is declared after Procedure A so doesn't exist when the compiler attempts to compile procedure A. If you comment procedure A out (including the call line), procedure B will compile fine though because both lists are declared before Procedure B.
In the long run, I will be using SQlite to save and track data, but how to have the data accessible to all windows I will have to figure out maybe with some help from people here after I give things another try. I need to learn SQlite stuff so I can use it also.
First number of windows I want to go through when the game is started:
Splash screen (click mouse to proceed)
Select game type (Manager, Coach or Load saved game)
Select number of players (1 - 8 then click "Ok" button)
Enter player names
Select league (English, French, German, Italian, Scottish, Spanish or Dutch)
Select team (According to what league you choose you can click through the divisions of that league and select a team)
Select Difficulty level
After the above listed splash screen and setup windows the actual game starts
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care
- Distorted Pixel
- Enthusiast

- Posts: 313
- Joined: Sun Aug 29, 2021 4:34 am
Re: Make data available to next opening window after current window closes
I will post some code soon when I get some done. Talking about things does help, but examples are visually better to see what is going on
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? 
No one cares how much you know until they know how much you care
No one cares how much you know until they know how much you care