How can i set default value for ES2Writer and reader?

Discussion and help for Easy Save 3
Post Reply
cragggle
Posts: 11
Joined: Mon Jun 10, 2019 4:05 am

How can i set default value for ES2Writer and reader?

Post by cragggle »

I have checked the docs, cannot find any reference to it for the reader and writer, only the other methods.

If I don't delete saves, add a new variable and load into the game, it defaults to some stupidly high number.
I found out I can use
if(reader.TagExists("myPosition"))
To solve the problem, but just curious if you can set defaults for the Reader/Writer as adding a new if statement for my 60+ variables + more to be added will just be a pain.
Happy to do it if no other options.

And sorry if it's obvious in the Docs, I have looked for a good 15 mins.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: How can i set default value for ES2Writer and reader?

Post by Joel »

Hi there,

There is no default value for ES2Writer/Reader. However, you could create a wrapper method which you could call so you don't have to use the if statement every time. Something along the lines of:
public T ReadDefault<T>(string tag, T defaultValue, ES2Reader reader)
{
    if(!reader.TagExists(tag))
        return defaultValue;
    return reader.Read<T>(tag);
}
Note this code is only provided as an example and has not been tested, but should give you a general idea.

Also note that this will only work if you are reading/writing data using tags. There is no way of knowing whether data exists when data is written sequentially as there is no formatting (which is why sequential is so much quicker).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
cragggle
Posts: 11
Joined: Mon Jun 10, 2019 4:05 am

Re: How can i set default value for ES2Writer and reader?

Post by cragggle »

Joel wrote:Hi there,

There is no default value for ES2Writer/Reader. However, you could create a wrapper method which you could call so you don't have to use the if statement every time. Something along the lines of:
public T ReadDefault<T>(string tag, T defaultValue, ES2Reader reader)
{
    if(!reader.TagExists(tag))
        return defaultValue;
    return reader.Read<T>(tag);
}
Note this code is only provided as an example and has not been tested, but should give you a general idea.

Also note that this will only work if you are reading/writing data using tags. There is no way of knowing whether data exists when data is written sequentially as there is no formatting (which is why sequential is so much quicker).

All the best,
Joel
Thanks for the reply and i appreciate the effort.
For now this seems a little complicated for my skill level So i think i'll just end up using the if statement for new variables added in updates when i release the app, as the problem only happens when updates happen without wiping save data.
I will come back and try and use this if i feel that i need it in the future.

Thanks
Post Reply