Changes

→‎Save data: merge new content into text
Line 27: Line 27:     
===Save data===
 
===Save data===
You can store arbitrary data in the current save file. This is mainly useful for save-specific data, like player progression and custom items. Note that a save file must be loaded (e.g. it won't work on the title screen), and the data won't be persisted until the player saves the current day.
+
You can store arbitrary data in the current save file. This is mainly useful for save-specific data, like player progression and custom items. This is subject to some restrictions: the save file must be loaded (e.g. it won't work on the title screen), it can't be used by farmhands in multiplayer (you can [[Modding:Modder Guide/APIs/Utilities#Context|check <tt>Context.IsMainPlayer</tt>]]), and it'll be discarded if the player exits without saving. If the data needs to be prepared prior to saving, the [[Modding:Modder Guide/APIs/Events#GameLoop.Saving|<tt>GameLoop.Saving</tt> event]] is a good time to do it.
    
<ol>
 
<ol>
Line 44: Line 44:  
Note that <tt>ReadSaveData</tt> will return <tt>null</tt> if the data doesn't exist.</li>
 
Note that <tt>ReadSaveData</tt> will return <tt>null</tt> if the data doesn't exist.</li>
 
</ol>
 
</ol>
  −
Save data can only be accessed by the master player, i.e. when playing single player or when hosting a multiplayer game. For farmhands these methods will throw an error. You can check whether the local player is the master player using <tt>Game1.IsMasterGame<tt>.
  −
  −
Note that the data passed to <tt>WriteSaveData</tt> is not directly written to disk, as it is embedded in the Stardew Valley save file. If the data being saved needs to be prepared prior to saving, the best moment to do so is during the Saving event, i.e. <tt>helper.Events.GameLoop.Saving</tt>, which is just before Stardew Valley writes the save game to disk.
      
===Global app data===
 
===Global app data===
translators
8,446

edits