Feedback about implementation

Discussion and help for Easy Save 3
Post Reply
devlucaslopes
Posts: 1
Joined: Tue Aug 30, 2022 10:12 am

Feedback about implementation

Post by devlucaslopes »

Hello guys, i wanna ask a feedback about this implementation...I'm creating a platformer game. When player get the checkpoint I will save: Collected Coins and Enemies Killed.

I'm create a script to management all saves. Also create unique keys using a prefix with SCENE BUILD INDEX + NAME for save this data about each level.

I'm using the position of gameobjects to save in the list. I not found some kind of ID unchanged and unique for get gameobjects. This aproch is wrong?

Code: Select all

    private void Awake()
    {
            COLLECTED_COINS = $"{_sceneIndex}_COLLECTED_COINS";
            ENEMIES_KILLED = $"{_sceneIndex}_ENEMIES_KILLED";

            _collectedCoins = ES3.Load(COLLECTED_COINS, _collectedCoins);
            _enemiesKilled = ES3.Load(ENEMIES_KILLED, _enemiesKilled);
    }

    public void NewCoinCollected (Vector3 position)
    {
        _collectedCoins.Add(position);
    }

    public bool FindCoinByPosition(Vector3 position)
    {
        return _collectedCoins.Exists(coin => Equals(coin, position));
    }

    public void EnemyKilled (Vector3 position)
    {
        _enemiesKilled.Add(position);
    }
    public bool FindEnemyByPosition(Vector3 position)
    {
        return _enemiesKilled.Exists(enemy => Equals(enemy, position));
    }

    public void SaveGameFromCheckpoint ()
    {
        ES3.Save(COLLECTED_COINS, _collectedCoins);
        ES3.Save(ENEMIES_KILLED, _enemiesKilled);
    }
When player restart the level I will check if this enemy or this coin was collected.

Code: Select all

        if (SaveController.Instance.FindCoinByPosition(transform.position))
            Destroy(gameObject);
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Feedback about implementation

Post by Joel »

Hi there,

I see no reason why your code shouldn’t work. You would just need to ensure that your load code runs before your code which checks whether the coins have been collected, and that your NewCoinCollected method is actually being called.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply