Langsung ke konten
Skillpedia
Pemrograman umum6.6k Β· #13804

save-systems

Fungsinya

Skill ini mencakup penyimpanan dan pemuatan kemajuan game, termasuk apa yang disimpan, penulisan file yang aman, dan versi. Skill ini ditujukan untuk pengembang game yang memerlukan penyimpanan yang tetap utuh setelah pembaruan.

Kapan dipakai

  • βœ“Saat Anda perlu menyimpan kemajuan pemain, inventaris, dan flag dunia di antara sesi.
  • βœ“Saat penyimpanan rusak setelah crash atau saat game terhenti ketika sedang menyimpan.
  • βœ“Saat file simpan lama berhenti berfungsi setelah Anda memperbarui game.

Link skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/save-systems/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/save-systems/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œPemain saya kehilangan file simpan ketika game crash saat menyimpan, dan simpanan lama rusak setelah pembaruan. Bisakah Anda memperbaiki sistem penyimpanannya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memutuskan data mana yang menjadi sumber kebenaran dan menyimpan data itu, bukan objek engine. Agent menambahkan nomor versi pada setiap simpanan, menulis file dengan cara yang tidak dapat dirusak oleh crash, dan menambahkan kode migrasi untuk versi yang lebih lama.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Save systems

A save file is a serialized snapshot of game state that survives restarts. The hard parts aren't writing bytes β€” they're choosing what to save, writing it so a crash mid-save can't corrupt it, and reading old saves after you ship a patch. Get those three right and the rest is plumbing.

When to use

  • Use to persist progress: player stats, inventory, world flags, settings, positions β€” across sessions and game updates.
  • Use to design save slots, quicksave/autosave, and crash-safe writes.
  • Use when old save files break after a content/code change (versioning & migration).

When not to use: for Roblox cloud persistence specifics, use roblox-datastores. For the data model the save serializes (resources/SOs), use godot-resources / unity-scriptableobjects. For Godot's FileAccess/ ResourceSaver and user:// paths, defer to the Godot engine skill while applying the patterns here.

Core workflow

  1. Decide what state is authoritative. Save the data (hp, position, seed, unlocked flags), not engine objects or scene nodes. You will reconstruct objects from data on load β€” never serialize live node references.
  2. Define a versioned schema. Every save embeds a version integer. This is the single most important field for a game you intend to patch.
  3. Pick a format. JSON/text for readability and debuggability; a binary format for size/speed or mild tamper-resistance. Start with JSON.
  4. Write atomically. Serialize to a temp file, flush, then rename over the real file. A crash leaves either the old save or the new one β€” never a half-written one.
  5. Load defensively. Read version β†’ migrate up to current β†’ validate β†’ instantiate. Keep a backup of the last good save and fall back on parse error.
  6. Autosave on safe boundaries (level change, checkpoint), throttled, and to a separate slot so it can't clobber a manual save.
  7. Verify: save, fully quit, relaunch, load β€” and confirm by inspection that state matches. Test loading a save from the previous version.

Patterns

1. Serialize state as plain data (not engine objects)

# Build a dictionary of pure data. Each savable object reports its own state.
func capture_state() -> Dictionary:
    return {
        "version": SAVE_VERSION,                 # ALWAYS stamp the schema version
        "player": { "hp": player.hp, "pos": [player.position.x, player.position.y] },
        "inventory": player.inventory.to_array(),  # ids + counts, not Item nodes
        "flags": world.flags,                    # e.g. {"met_guard": true}
        "seed": world.seed,                      # regenerate procedural content
    }

# On load, RECONSTRUCT objects from the data β€” do not expect live references back.
func apply_state(data: Dictionary) -> void:
    player.hp = data["player"]["hp"]
    player.position = Vector2(data["player"]["pos"][0], data["player"]["pos"][1])
    player.inventory.from_array(data["inventory"])
    world.flags = data["flags"]

2. Atomic, crash-safe write (temp + rename)

# Godot 4.7. Write a temp file, keep the previous save as .bak, then rename.
func save_atomic(path: String, data: Dictionary) -> Error:
    var tmp := path + ".tmp"
    var f := FileAccess.open(tmp, FileAccess.WRITE)
    if f == null:
        return FileAccess.get_open_error()       # disk full, read-only, no permission...
    if not f.store_string(JSON.stringify(data)):
        return ERR_FILE_CANT_WRITE
    f.close()                                    # flushes Godot's buffer to the OS
    if FileAccess.file_exists(path):
        DirAccess.rename_absolute(path, path + ".bak")   # keep the last good save
    return DirAccess.rename_absolute(tmp, path)

func load_save(path: String) -> Dictionary:      # empty = nothing loadable
    for p in [path, path + ".bak"]:              # .bak covers a crash between renames
        if FileAccess.file_exists(p):
            var data = JSON.parse_string(FileAccess.get_file_as_string(p))
            if data is Dictionary and data.has("version"):
                data["version"] = int(data["version"])   # JSON numbers load as float
                return data
    return {}
# WRONG: opening `path` directly and writing in place β€” a crash mid-write leaves a
# truncated, unloadable save and destroys the player's progress.

A crash now leaves the old save, the new one, or (between the two renames) only the .bak β€” which the loader tries

Pertanyaan umum

Mengapa menambahkan nomor versi pada setiap simpanan?

Skill menyebutnya field paling penting, karena memungkinkan pembaruan di masa depan mengonversi simpanan lama.

Haruskah saya menyimpan objek scene?

Tidak. Skill menyebutkan untuk menyimpan data dan membangun ulang objek dari data itu saat dimuat.

Apakah mencakup penyimpanan Roblox?

Tidak. Data store Roblox dicakup oleh skill Roblox yang terpisah.

Detail

Deskripsi asli dari pembuat

Design save/load for game state β€” choosing what to serialize, file formats, save slots, atomic crash-safe writes, schema versioning and migration, and autosave. Engine-neutral. Use when the user mentions save system, save/load, game state persistence, save slots, autosave, save file corruption, or migrating old saves to a new version.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularitas

Bintang GitHub
6.6k
Peringkat
#13804
Lisensi
Apache-2.0
Diperbarui
28/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa