Global arrays

For questions about using Classic.

Post » Wed Aug 20, 2008 3:05 pm

So I've been trying to make a game with save/load capability using a global array, but it is acting really strange. In every layout I have a copy of the same array with the "Global" flag on. The first layout is a main menu where the array is loaded from a file, or if New Game is selected, default values are set to it. In the second layout I have a simple game where you can touch a save point to save all data in the array to a file. But for some reason it is not saving the data properly. Here's a brief summary of what I'm doing:

1. In the first layout, I press the "New Game" button. This sets the values of the array to what they should be at the beginning of the game. Then it goes to the next layout.
2. In the second layout, I have a few counters that show the data in the array, and they show the correct values right now. I walk up to a save point and save the array to "leet.sav" in the game's directory. Then I restart the game.
3. I'm back at the first layout. I press the "Load Game" button and it checks to see if "leet.sav" exists, if that is true, it loads the data from that file and jumps to the next layout.
4. Now, when I'm in the second layout, all of the counters display 0. Zero.

What could be the cause of this? I'm not sure if it's the save or the load process that drops the values, but I cannot work any further until I fix this.

I have added a debug event that says "On key Z pressed: Array Set index (1,1) to index (1,1)+1". So when I press that button one of the counters is increased by 1. This number is displayed properly in the counter on the screen. I save the data and restart the app. When I go back and load the data, guess what? All the *other* counters are at zero, while the counter I increased has retained its added value, but lost the value it had before I started adding to it.
B
4
S
1
G
6
Posts: 28
Reputation: 2,056

Post » Wed Aug 20, 2008 8:45 pm

[quote="Nillo":ipk14z1x]So I've been trying to make a game with save/load capability using a global array[/quote:ipk14z1x]
Why not use the System object's save/load actions? They can save the entire game state to disk.

[quote:ipk14z1x]In every layout I have a copy of the same array with the "Global" flag on.[/quote:ipk14z1x]
You should only need one array object, in the first layout, with Global enabled. Then, unless you destroy it, the same instance continues to exist the lifetime of the application. If you put other instances in other layouts, these are spawned the first time the layout is opened, and then you have multiple instances of arrays each with their own data, which might cause problems.

Ticking global should cause it to appear in the event sheet editors for all layouts. If it doesn't, it's a bug.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,620

Post » Wed Aug 20, 2008 11:21 pm

[quote="Ashley":28kb1ga6]If it doesn't, it's a bug.[/quote:28kb1ga6]
It doesn't. Nor does anything else (mousekeyboard directsound etc)
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Thu Aug 21, 2008 12:29 am

[quote="Ashley":15o2a4tm]Why not use the System object's save/load actions? They can save the entire game state to disk.[/quote:15o2a4tm]I suppose, but I feel that I have more control when I am specifying the exact values I want to save to the file. I don't really need to know what's going on in the current game, just the player's X and Y position, hit points and other stats.

I've removed all except one of the array objects now, and it seems to be working properly - however, as faggatron mentioned, I can't see the array in the event sheet editor now.
B
4
S
1
G
6
Posts: 28
Reputation: 2,056


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests