Skip to main content
Cleanup
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

how How do iI save data offor multiple things sharing the same script?

I have level 0 rusted sword, ithen I upgrade it... and save my game.

I implemented my save system by following godotGodot tutorials on save data. But with this approach, after openingexiting and re-launching the game, all rusted swords in the game are now upgraded.

What do I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

myMy current system is shit I'll gladly rework it.

but as of now it's works like this:

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

andAnd I reverse the order for dropping items, which ofcourseof course means that item idID changes every time it is dropped and instanced again, so using itthat is problematic.

func savePlayerData():
    var data = {
       "strength": strength,}
    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)
    var file = File.new()
    var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
    if error == OK:
        file.store_var(data)
        file.close()

 

func loadPlayerData():
    var file = File.new()
    if file.file_exists(save_path):
        var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
        if error == OK:
            var player_data = file.get_var()
            file.close()
            if "strength" in player_data:
                strength = player_data["strength"]

how do i save data of multiple things sharing the same script?

I have level 0 rusted sword, i upgrade it.... by following godot tutorials on save data after opening the game all rusted swords in the game are now upgraded.

What I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

my system is shit I'll gladly rework it.

but as of now it's :

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

and reverse order for dropping items, which ofcourse means that item id changes every time it is dropped and instanced again, so using it is problematic

func savePlayerData():
    var data = {
       "strength": strength,}
    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)
    var file = File.new()
    var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
    if error == OK:
        file.store_var(data)
        file.close()

 

func loadPlayerData():
    var file = File.new()
    if file.file_exists(save_path):
        var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
        if error == OK:
            var player_data = file.get_var()
            file.close()
            if "strength" in player_data:
                strength = player_data["strength"]

How do I save data for multiple things sharing the same script?

I have level 0 rusted sword, then I upgrade it and save my game.

I implemented my save system by following Godot tutorials. But with this approach, after exiting and re-launching the game, all rusted swords in the game are now upgraded.

What do I have to do so that only that specific sword is upgraded?

My current system works like this:

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

And I reverse the order for dropping items, which of course means that item ID changes every time it is dropped and instanced again, so using that is problematic.

func savePlayerData():
    var data = {
       "strength": strength,}
    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)
    var file = File.new()
    var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
    if error == OK:
        file.store_var(data)
        file.close()

func loadPlayerData():
    var file = File.new()
    if file.file_exists(save_path):
        var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
        if error == OK:
            var player_data = file.get_var()
            file.close()
            if "strength" in player_data:
                strength = player_data["strength"]
added 731 characters in body
Source Link

I have level 0 rusted sword, i upgrade it.... by following godot tutorials on save data after opening the game all rusted swords in the game are now upgraded.

What I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

my system is shit I'll gladly rework it.

but as of now it's :

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

and reverse order for dropping items, which ofcourse means that item id changes every time it is dropped and instanced again, so using it is problematic

func savePlayerData():
    var data = {
       "strength": strength,}
    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)
    var file = File.new()
    var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
    if error == OK:
        file.store_var(data)
        file.close()



func loadPlayerData():
    var file = File.new()
    if file.file_exists(save_path):
        var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
        if error == OK:
            var player_data = file.get_var()
            file.close()
            if "strength" in player_data:
                strength = player_data["strength"]

I have level 0 rusted sword, i upgrade it.... by following godot tutorials on save data after opening the game all rusted swords in the game are now upgraded.

What I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

my system is shit I'll gladly rework it.

but as of now it's :

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

and reverse order for dropping items, which ofcourse means that item id changes every time it is dropped and instanced again, so using it is problematic

I have level 0 rusted sword, i upgrade it.... by following godot tutorials on save data after opening the game all rusted swords in the game are now upgraded.

What I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

my system is shit I'll gladly rework it.

but as of now it's :

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

and reverse order for dropping items, which ofcourse means that item id changes every time it is dropped and instanced again, so using it is problematic

func savePlayerData():
    var data = {
       "strength": strength,}
    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)
    var file = File.new()
    var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
    if error == OK:
        file.store_var(data)
        file.close()



func loadPlayerData():
    var file = File.new()
    if file.file_exists(save_path):
        var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
        if error == OK:
            var player_data = file.get_var()
            file.close()
            if "strength" in player_data:
                strength = player_data["strength"]
Source Link

how do i save data of multiple things sharing the same script?

I have level 0 rusted sword, i upgrade it.... by following godot tutorials on save data after opening the game all rusted swords in the game are now upgraded.

What I have to do so that only that specific sword is upgraded? Please don't answer to "depends on your system"

my system is shit I'll gladly rework it.

but as of now it's :

detect item on floor:
       press key to pick:
        check what type of item it is:
          check if item slot is viable:
              delete item from floor, add into the item slot 
         

and reverse order for dropping items, which ofcourse means that item id changes every time it is dropped and instanced again, so using it is problematic