I have started scripting the third scenario for the frisians campaign. One feature I really want to use (planning ahead here) is saving campaign data between scenarios. Basically, I want to save certain information to a file when scenario #3 is completed, and read it from there in scenario #4 to reuse it.
In normal Lua, I can write to a file like this:
function save_campaign_data(filename, text) local file = io.open(filename, "w") for i,t in ipairs(text) do file:write(t) end file:close() end
If I need to create the directory structure first, I can use
os.execute("mkdir " .. name)
(this works on Linux and Windows; is there an OS where it won´t?)
When using those in a Widelands scenario script, the game crashes with
Trying to run: map:scripting/init.lua: Scenario not started: Game data error: lua: [../src/scripting/lua_errors.cc:22] [string "scripting/campaign_data.lua"]:51: attempt to index a nil value (global 'os')
The same message also appears for "… (global 'io')".
So my first question is: What do I need to do to use "io" and "os" in my Widelands scenario?
My second question is: Campaign data files should be stored in the Widelands home directory, e.g. in "~/.widelands/campaigns/frisians/fri03.wcd". How can I get the path to the home directory in the script?