I’m self-taught so I’m a little lacking in expertise. I know that Godot doesn’t have the traditional try/catch so I’m trying to figure out how to detect this error.
My Android game has a a memory file, it works perfectly. Some example variables:
game_memory.total_games_played:int = 0
game_memory.total_games_won:int = 0
game_memory.high_score:int = 0
So now it has come to the point I wish to add a new variable to memory, for example:
game_memory.best_time:int
For the people who have already have the game on their phones, the file saved to memory will not have a “best_time” variable in the memory file, so if I push out a new game update that attempts to access such variable it will crash/ANR the game.
During testing I get the error when I attempt to access a new best_time variable:
Invalid access to property or key 'best_time' on base object type Resource(Memory)
OK, this all makes sense, I expect this. My issue is how can I test that the property of key exists so I run code to create a new memory file and use it to save over the old one? I really don’t want to create file and then have to manage 2 files in my game - that seems like bad coding.
I have tried potential solutions such as:
if game_memory.best_time == null
if is_instance_valid(game_memory.best_time)
But none of these work. I just need a way to do something like this:
try:
var test:int = game_memory.best_time
catch:
func_to_update_memory_file_to_include_new_variables()
Can something like this be achieved in Godot? Thanks