Global arrays

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So I've been trying to make a game with save/load capability using a global array

    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.

    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.

  • If it doesn't, it's a bug.

    It doesn't. Nor does anything else (mousekeyboard directsound etc)

  • Why not use the System object's save/load actions? They can save the entire game state to disk.

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)