Strange Characters When Saving Game's Data?


#1

Hi,

I have the following code in the “init” of the title screen:
(code saves game options and high scores)

	local GameOptionsAndHighScoresTable = {}
	table.insert(GameOptionsAndHighScoresTable, MusicVolume)
	table.insert(GameOptionsAndHighScoresTable, SoundVolume)
	table.insert(GameOptionsAndHighScoresTable, GameMode)
	for mode = 0, 2 do
		for rank = 0, 9 do
			table.insert(GameOptionsAndHighScoresTable, HighScoresName[mode][rank])
			table.insert(GameOptionsAndHighScoresTable, HighScoresLevel[mode][rank])
			table.insert(GameOptionsAndHighScoresTable, HighScoresScore[mode][rank])
		end
	end 
	local my_file_path = sys.get_save_file("RedLightRacer", "RLR_PreAlpha1.cfg")
	if not sys.save(my_file_path, GameOptionsAndHighScoresTable) then
		print("Save Failed!")
	end

If I run the game it does produce a “RLR_PreAlpha1.cfg” in folder “RedLightRacer”,
but the data has strange characters and is unreadable by the game?

Code builds with no errors, and as said above it it creating a game data save file…

Thanks!

J.

Also…
Here is the load game data code:

    local my_file_path = sys.get_save_file("RedLightRacer", "RLR_PreAlpha1.cfg")
    local GameOptionsAndHighScoresTable = sys.load(my_file_path)
    if not next(GameOptionsAndHighScoresTable) then
        print("Game data file not found.")
    end
    MusicVolume = table.remove(GameOptionsAndHighScoresTable, 0)
    EffectsVolume = table.remove(GameOptionsAndHighScoresTable, 0)
    GameMode = table.remove(GameOptionsAndHighScoresTable, 0)
    for mode = 0, 2 do
        for rank = 0, 9 do
            HighScoresName[mode][rank] = table.remove(GameOptionsAndHighScoresTable, 0)
            HighScoresLevel[mode][rank] = table.remove(GameOptionsAndHighScoresTable, 0)
            HighScoresScore[mode][rank] = table.remove(GameOptionsAndHighScoresTable, 0)
        end
    end	

#2

What do you mean by “it is unreadable by the game”? What errors are you receiving?

The data is not supposed to be human-readable.


#3

Ok, so the table that is saved is encrypted, that is ok.
But when I run above code (2nd one) to load the game’s data it’s not what the game is expecting?
ie: the game crashes on title screen when trying to display top high score name & top high score score.

J.


#4

It’s not encrypted, it’s a binary representation of the lua table you passed to it.

Tip: After loading the data, try printing it out:

pprint(GameOptionsAndHighScoresTable)

#5

Ok, it works now, many thanks!

Game’s “shell” is about finished now - will start the actual game in a couple of days.
As always the finished game will be released open-source…

Thanks!

J.


#6

Good luck with the game!

As always, if you get stuck, consult the manual, and search through the forums, since chances are very high someone will have asked the same thing as you before! If none of that checks out, then we’re here to help.