User Tools

Site Tools


en:tutorials:config:save_games

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:save_games [2018/01/10 23:53 (6 years ago)] – marked up sausageen:tutorials:config:save_games [2020/08/31 05:44 (4 years ago)] (current) – ↷ Page moved from en:tutorials:save_games to en:tutorials:config:save_games sausage
Line 1: Line 1:
-====== Saving Game information to the Config ====== 
- 
-As well as loading information from a config file, you can also save your own sections back to a separate config file. 
- 
-This can be used to persist score or player information to a file that can be loaded when the player returns to your game. 
- 
-There is currently no specific guide on this page to take you through the process. In lieu of that, the following link takes you to the API where you can get familiar with what config functions are available for working with config files:  
- 
-http://orx-project.org/orx/doc/html/group__orx_config.html 
- 
-You might be able to glean some usage examples from this project file:  
- 
-https://bitbucket.org/sausage/xerop/src/5fbf06b1aea0ddfbb1c1403481b4713ebea1721a/pinball/src/pinball/pinballbase.cpp?at=master&fileviewer=file-view-default 
- 
-Look for the **LoadSavedHighScores** and **SaveHighScoresToConfig** functions. 
- 
-Also, make sure you don't miss the detail outlined on the [[en:orx:config:main#general_information|Config]] page 
- 
-Hopefully a proper tutorial can be put together soon. If you'd like to write one, please feel free to replace this page. 
- 
- 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
- 
-. 
- 
- 
- 
- 
- 
-<WRAP center round box 60%> 
-The following is draft information, pending release. 
-</WRAP> 
- 
- 
 ====== Saving Game information to a Config File ====== ====== Saving Game information to a Config File ======
  
-As well as loading information from a config file, you can also save the content of config in memory to a file, either completely or partially. +As well as loading information from a config file, you can also save the config in memory (completely or partially) to a file
  
 This can be used for all manner of things like persisting scores, player information or any game information to a file that can be loaded back later. This can be used for all manner of things like persisting scores, player information or any game information to a file that can be loaded back later.
Line 95: Line 12:
  
   - The first parameter is the filename you wish to save your config to. The extension can be anything you like. I usually just stick to ''ini''   - The first parameter is the filename you wish to save your config to. The extension can be anything you like. I usually just stick to ''ini''
-  - The second parameter indicates if the file is to be written encrypted so that it won't be human readable. +  - The second parameter indicates if the file is to be written encrypted so that it won't be human readable. Handy for stopping game cheaters
-  - The last parameter is a callback that will be called for every section and every key to let you decide if you want to save this info to the file or not.+  - The last parameter is a callback function that will be called for every section and every key to let you decide if you want to save this info to the file or not.
  
 If you pass orxNULL instead of a valid callback, every single key/value pair will be saved. If you pass orxNULL instead of a valid callback, every single key/value pair will be saved.
  
-Please note that the any comments within originally loaded files won't be saved. They're ignored during loading and never stored in memory.+<WRAP center round box 90%> 
 +Please note that the any comments within the original loaded config files won't be saved. They're ignored during loading and never stored in memory. 
 +</WRAP>
  
-Let's work through an example.+Let's work through a saving example.
  
 Just say we had an initial config loaded by your game that was something like this: Just say we had an initial config loaded by your game that was something like this:
Line 123: Line 42:
 When your Orx game loads, this config would be loaded into memory. When your Orx game loads, this config would be loaded into memory.
  
-You can then add to the config that is in memory. To add something like a highscore value to the config in memory, we could do it with:+You can then add to the config that is in memory. To add something like a highscore value to the config in memory, we can do it with:
  
 <code c> <code c>
Line 132: Line 51:
 </code> </code>
  
-This would be added to the config in memory and the entire result would be:+This would be added to the config in memory and the entire result would become:
  
 <code ini> <code ini>
Line 152: Line 71:
 </code> </code>
  
-We could save the entire config in memory to an external file with:+We could then save the entire config in memory to an external file with:
  
 <code c> <code c>
Line 162: Line 81:
 This is where the callback filter comes into play. This is where the callback filter comes into play.
  
-In your ''MySaveFilter'' callback (which is called many times by ''orxConfig_Save''), the section and keys are provided+Your ''MySaveFilterCallback'' callback which is called many times by ''orxConfig_Save'' for each section and key.
  
-It is for you to decide, in code, if you want to save some parts of this section (by returning orxTRUE) or if you'd rather skip the whole section completely (by returning orxFALSE).+This allows you to decide, in code, if you want to save some parts of this section (by returning orxTRUE) or if you'd rather skip the whole section completely (by returning orxFALSE).
  
 This may not be very clear, so lets look at an example callback: This may not be very clear, so lets look at an example callback:
Line 181: Line 100:
 This will filter out all the config sections that are in memory, except for the ''SaveSettings'' section. So if you call: This will filter out all the config sections that are in memory, except for the ''SaveSettings'' section. So if you call:
  
-'orxConfig_Save("MySavedConfigFile.ini", orxFALSE, MySaveFilterCallback);'+<code c> 
 +orxConfig_Save("MySavedConfigFile.ini", orxFALSE, MySaveFilterCallback); 
 +</code>
  
-Then only the ''SaveSettings'' section will appear in your ''ySavedConfigFile.ini'' file.+Then only the ''SaveSettings'' section will appear in your ''SavedConfigFile.ini'' file.
  
 Of course, to load your save file back, simply do a: Of course, to load your save file back, simply do a:
Line 194: Line 115:
  
  
-==== Saving only certain Keys in a Section ====+==== Saving only certain filtered Keys from a Section ====
  
-In order to save only a particular key from a config (instead of saving all keys from a config, we need to change our callback. Let's say our ''SaveSettings'' sections contained two keys:+In order to save only a particular key or keys from a config (instead of saving all keys from a config, we need to change our callback. Let's say our ''SaveSettings'' section contained two keys:
  
 <code ini>  <code ini> 
Line 204: Line 125:
 </code> </code>
  
-If we only wanted the ''LastLevel'' key to be saved with the section out to the file, the callback would look like this:+If we only wanted the ''LastLevel'' key to be saved out to the file, the callback would look like this:
  
 <code c> <code c>
Line 218: Line 139:
 </code> </code>
  
-In the code above, compare to the section name to get the ''SaveSettings''The comparing of ''_zKeyName'' to orxNULL will get the section name. Then the comparing to ''LastLevel'' will get the specific key.+In the code above, we compare the section name to find ''SaveSettings''Then the comparing of ''_zKeyName'' to orxNULL will get the section name itself. Then the comparing to ''LastLevel'' will get the specific key.
  
  
 ==== More information ==== ==== More information ====
  
-There is a lot more that the config API can do. You can get familiar with what config functions are available at: +There is a lot more that the config API can do. You can explore more config functions at: 
  
 http://orx-project.org/orx/doc/html/group__orx_config.html http://orx-project.org/orx/doc/html/group__orx_config.html
  
-There are some usage examples in the Orx Curve Editor that is undergoing development at: https://bitbucket.org/sausage/orx-curvefx-editor +There are some usage examples available in the Orx Curve Editor that is currently in development at: https://gitlab.com/sausagejohnson/orx-curvefx-editor
- +
-Also, make sure you don't miss the detail outlined on the [[en:orx:config:main#general_information|Config]] page. +
- +
- +
  
 +Also, don't forget there are a number of other config [[http://orx-project.org/wiki/tutorials/main#config|tutorials]] available.
en/tutorials/config/save_games.1515657203.txt.gz · Last modified: 2018/01/11 03:53 (6 years ago) (external edit)