Changes

Jump to navigation Jump to search
+ deletion
Line 35: Line 35:     
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
// read file
+
// read data
 
var model = this.Helper.Data.ReadSaveData<ModData>("example-key");
 
var model = this.Helper.Data.ReadSaveData<ModData>("example-key");
   −
// save file (if needed)
+
// save data (if needed)
 
this.Helper.Data.WriteSaveData("example-key", model);
 
this.Helper.Data.WriteSaveData("example-key", model);
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 54: Line 54:     
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
// read file
+
// read data
 
var model = this.Helper.Data.ReadGlobalData<ModData>("example-key");
 
var model = this.Helper.Data.ReadGlobalData<ModData>("example-key");
   −
// save file (if needed)
+
// save data (if needed)
 
this.Helper.Data.WriteGlobalData("example-key", model);
 
this.Helper.Data.WriteGlobalData("example-key", model);
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 111: Line 111:  
==Data key==
 
==Data key==
 
A ''data key'' identifies your data, which lets you access the data again later. It should be unique within your mod, but there's no need to worry about conflicts with other mods (SMAPI will namespace the key internally). A data key can only contain letters, numbers, underscores, hyphens, or dots.
 
A ''data key'' identifies your data, which lets you access the data again later. It should be unique within your mod, but there's no need to worry about conflicts with other mods (SMAPI will namespace the key internally). A data key can only contain letters, numbers, underscores, hyphens, or dots.
 +
 +
==Deletion==
 +
To remove an entry or file, just pass <code>null</code> as the data model. This works with any of the <tt>Write*</tt> methods except <tt>WriteJsonFile</tt> ({{SMAPI upcoming|3.13.0|inline=1|fixed}}):
 +
<syntaxhighlight lang="c#">
 +
// delete entry (if present)
 +
this.Helper.Data.WriteSaveData<DataModel>("example-key", null);
 +
</syntaxhighlight>
translators
8,446

edits

Navigation menu