This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:save_games [2018/01/10 23:53 (6 years ago)] – marked up sausage | en: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:// | ||
- | |||
- | You might be able to glean some usage examples from this project file: | ||
- | |||
- | https:// | ||
- | |||
- | Look for the **LoadSavedHighScores** and **SaveHighScoresToConfig** functions. | ||
- | |||
- | Also, make sure you don't miss the detail outlined on the [[en: | ||
- | |||
- | 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, | ||
- | </ | ||
- | |||
- | |||
====== 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 | + | As well as loading information from a config file, you can also save the config in memory |
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 '' | - 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 '' | ||
- | - 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 |
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 | + | <WRAP center round box 90%> |
+ | Please note that the any comments within | ||
+ | </ | ||
- | Let's work through | + | Let's work through |
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: | ||
</ | </ | ||
- | 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: | ||
</ | </ | ||
- | 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 '' | + | Your '' |
- | 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 |
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 '' | This will filter out all the config sections that are in memory, except for the '' | ||
- | 'orxConfig_Save(" | + | <code c> |
+ | orxConfig_Save(" | ||
+ | </ | ||
- | Then only the '' | + | Then only the '' |
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 |
- | 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 '' | + | 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 '' |
<code ini> | <code ini> | ||
Line 204: | Line 125: | ||
</ | </ | ||
- | If we only wanted the '' | + | If we only wanted the '' |
<code c> | <code c> | ||
Line 218: | Line 139: | ||
</ | </ | ||
- | In the code above, compare | + | In the code above, |
==== More information ==== | ==== More information ==== | ||
- | There is a lot more that the config API can do. You can get familiar with what config functions | + | There is a lot more that the config API can do. You can explore more config functions at: |
http:// | http:// | ||
- | There are some usage examples in the Orx Curve Editor that is undergoing | + | There are some usage examples |
- | + | ||
- | Also, make sure you don't miss the detail outlined on the [[en: | + | |
- | + | ||
- | + | ||
+ | Also, don't forget there are a number of other config [[http:// |