Topic: Scenarios: File I/O
| GunChleoc   | Posted at:
        
            
    2018-04-18, 08:50 UTC+2.0 The mechanics should work for leveling out the difficulty. After leveling out the benefits, good players should still end up with a slight advantage as a reward, but not too much. Busy indexing nil values  Top  Quote | 
| Nordfriese   Topic Opener | Posted at:
        
            
    2018-04-21, 17:00 UTC+2.0 
 More or less, at the current state of the branch. If the Widelands homedir is the default location, the campaign_data.lua script works fine. I´m implementing   Top  Quote | 
| GunChleoc   | Posted at:
        
            
    2018-04-21, 18:22 UTC+2.0 I think we should have a directory under .widelands for this. Have a look at the savehandler or at how options get stored - you should be able to find some code there for picking/setting up a directory. Busy indexing nil values  Top  Quote | 
| Nordfriese   Topic Opener | Posted at:
        
            
    2018-04-22, 18:21 UTC+2.0 Completely new approach. Instead of using a Lua aux script, I have now implemented two functions of EditorGameBase in C++ : The C++ code takes care of all file I/O and directory structures, so there´s no need to allow scripts to use  The campaign data file is saved in  For the write access, I first tried to understand the save handler, but the packet structure seemed unnecessarily complex for writing a few lines of text. Instead, I based my code on how AI-DNA files are dumped. I´m using  As this is going rather beyond just scripting a scenario, I have created a new branch for this: lp:~widelands-dev/widelands/campaign_data.  Top  Quote | 
| hessenfarmer   | Posted at:
        
            
    2018-04-22, 19:14 UTC+2.0 sounds good how could the functions be assessed in the scenario?  Top  Quote | 
| Nordfriese   Topic Opener | Posted at:
        
            
    2018-04-22, 22:36 UTC+2.0 A brief usage example. Let´s say you want the player to start the 4th frisian scenario with as many logs and bricks as he had when he ended the 3rd scenario. In the third scenario, the following code is called when the scenario ends: This creates the file  The fourth scenario then gets this code near the beginning: Some notes: 
 I recommend as syntax that all information is stored as key/value pairs, and there is one key and one value per line, separated by "=". Having one "informal" syntax as standard helps if someone wants to read campaign data from someone else´s scenario. I´ll test the code some more, then I´ll open a merge request…  Top  Quote | 
| hessenfarmer   | Posted at:
        
            
    2018-04-22, 23:06 UTC+2.0 Nice work thanks.   Top  Quote | 
| GunChleoc   | Posted at:
        
            
    2018-04-23, 10:54 UTC+2.0 The new concept looks great  One more idea: rather than passing a string, why not use Lua tables? This way, the data structure will remain a data structure, like this: And then you can load it again with: This will need more effort on the C++ side, but make scenario scripting much easier. We could also have a table with 2 tables for wares and workers, with 2 corresponding sections in the profile. Busy indexing nil values  Top  Quote | 
| Nordfriese   Topic Opener | Posted at:
        
            
    2018-04-25, 14:03 UTC+2.0 Uploaded a new revision to the branch. Campaign data is now saved as one table. Strings, integers and booleans are permitted as values; all keys have to be strings. Example: The saving works correctly, though the table entries are saved in random order. I´m guessing this is the fault of  I could use some help how to return a table. Adding  Here is my code (line 434ff), and here (line 4583ff) is the code I´m using as example for creating lua tables with specified keys and values. What do I need to do different here?  Top  Quote | 
| GunChleoc   | Posted at:
        
            
    2018-04-27, 18:45 UTC+2.0 My development machine is back in action, so I'll take a look as soon as I can. Busy indexing nil values  Top  Quote | 

 
         
		 
		 
		 
		
