Jump to content

Recommended Posts

Posted

Is it possible to export and import data to and from a file? I’m trying to make a simple counter of units killed stay persistant between mission.

Posted

You can use this site LOGbook | Record your flight simulator progress (ansirial.it)  Download the application from the site and save every mission file after every mission you complete and upload it through the application. It keeps hours flown, hours in plane, unit kills ect.. 

 

John.

I feel the need The need for jet engines to create thrust in order to have differential pressure on the wings which achieves aerodynamics lift at high velocity Ooww!! :pilotfly:

An expert is someone who knows each time more on each time less, until he finally knows absolutely everything about absolutely nothing.

 

Posted

Gotta do what all of the persistence scripts use by modifying your missionScripting.lua file so you have access to the io and lfs libraries. 

 

Using lfs you can get data about different drives. Typically I just use it to get the saved games location to save a file in logs, scripts, or wherever else. 

 

local defaultDrive= lfs.writedir() .. [[Scripts\]]

 

Then you can use io.open, dofile, or there are probably others to be able to load the contents of a given file.  

 

 

To save it the easiest way is to just write the whole file in one go. That typically looks like

local myTable = {['player1Stats'] = {['kills'] = 5, ['RIOsKilledDueToFlatspins'] = 1}}
local wFile = io.open(defaultDrive .. fileName, 'w')
wFile:write(mist.utils.serialize('myTable', myTable))
wFile:close()
wFile = nil

 

Depending on how you load it or wanna write to the file then things can get pretty complicated quickly.  For instance I tend to use something copied out of slmod where it is closer to "streaming" where it writes line by line as things happen. After a while you end up with the lua file filled with the same entry listed multiple times, except for the value was changed. When the table gets loaded by DCS it just reads the last written value as the actual one. But as long as you aren't writing stupidly massive files extremely often it doesn't do a ton of harm to periodically write the whole file in one go. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...