Updated errors when LFS is nil

Statfile should not be used when lfs is null.

Also, modified Moose.lua to the correct directory.
This commit is contained in:
svenvandevelde 2016-01-20 20:53:44 +01:00
parent a391ca6ef3
commit 9f830fd768
2 changed files with 22 additions and 16 deletions

View File

@ -626,14 +626,16 @@ local nSeconds = sSeconds
end
function DATABASE:ScoreOpen()
local fdir = lfs.writedir() .. [[Logs\]] .. "Player_Scores_" .. os.date( "%Y-%m-%d_%H-%M-%S" ) .. ".csv"
self.StatFile, self.err = io.open(fdir,"w+")
if not self.StatFile then
error( "Error: Cannot open 'Player Scores.csv' file in " .. lfs.writedir() )
if lfs then
local fdir = lfs.writedir() .. [[Logs\]] .. "Player_Scores_" .. os.date( "%Y-%m-%d_%H-%M-%S" ) .. ".csv"
self.StatFile, self.err = io.open(fdir,"w+")
if not self.StatFile then
error( "Error: Cannot open 'Player Scores.csv' file in " .. lfs.writedir() )
end
self.StatFile:write( '"Run-ID";Time;"PlayerName";"ScoreType";"PlayerUnitCoaltion";"PlayerUnitCategory";"PlayerUnitType"; "PlayerUnitName";"TargetUnitCoalition";"TargetUnitCategory";"TargetUnitType";"TargetUnitName";Times;Score\n' )
self.RunID = os.date("%y-%m-%d_%H-%M-%S")
end
self.StatFile:write( '"Run-ID";Time;"PlayerName";"ScoreType";"PlayerUnitCoaltion";"PlayerUnitCategory";"PlayerUnitType"; "PlayerUnitName";"TargetUnitCoalition";"TargetUnitCategory";"TargetUnitType";"TargetUnitName";Times;Score\n' )
self.RunID = os.date("%y-%m-%d_%H-%M-%S")
end
function DATABASE:ScoreAdd( PlayerName, ScoreType, ScoreTimes, ScoreAmount, PlayerUnitName, PlayerUnitCoalition, PlayerUnitCategory, PlayerUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
@ -685,15 +687,19 @@ function DATABASE:ScoreAdd( PlayerName, ScoreType, ScoreTimes, ScoreAmount, Play
TargetUnitName = ''
end
self.StatFile:write( '"' .. self.RunID .. '";' .. ScoreTime .. ';"' .. PlayerName .. '";"' .. ScoreType .. '";"' ..
PlayerUnitCoalition .. '";"' .. PlayerUnitCategory .. '";"' .. PlayerUnitType .. '";"' .. PlayerUnitName .. '";"' ..
TargetUnitCoalition .. '";"' .. TargetUnitCategory .. '";"' .. TargetUnitType .. '";"' .. TargetUnitName .. '";' ..
ScoreTimes .. ';' .. ScoreAmount )
self.StatFile:write( "\n" )
if lfs then
self.StatFile:write( '"' .. self.RunID .. '";' .. ScoreTime .. ';"' .. PlayerName .. '";"' .. ScoreType .. '";"' ..
PlayerUnitCoalition .. '";"' .. PlayerUnitCategory .. '";"' .. PlayerUnitType .. '";"' .. PlayerUnitName .. '";"' ..
TargetUnitCoalition .. '";"' .. TargetUnitCategory .. '";"' .. TargetUnitType .. '";"' .. TargetUnitName .. '";' ..
ScoreTimes .. ';' .. ScoreAmount )
self.StatFile:write( "\n" )
end
end
function LogClose()
self.StatFile:close()
if lfs then
self.StatFile:close()
end
end
_Database = DATABASE:New()

View File

@ -12,7 +12,7 @@ end
Include = {}
Include.MissionPath = script_path() .. "Mission\\"
Include.ProgramPath = "Scripts\\Moose\\"
Include.ProgramPath = "Scripts\\Moose\\Moose\\"
env.info( "Include.MissionPath = " .. Include.MissionPath)
env.info( "Include.ProgramPath = " .. Include.ProgramPath)
@ -21,9 +21,9 @@ Include.Files = {}
Include.File = function( IncludeFile )
if not Include.Files[ IncludeFile ] then
Include.Files[IncludeFile] = IncludeFile
local f = base.loadfile( Include.MissionPath .. IncludeFile .. ".lua" )
local f = base.loadfile( Include.ProgramPath .. IncludeFile .. ".lua" )
if f == nil then
local f = base.loadfile( Include.ProgramPath .. IncludeFile .. ".lua" )
local f = base.loadfile( Include.MissionPath .. IncludeFile .. ".lua" )
if f == nil then
error ("Could not load MOOSE file " .. IncludeFile .. ".lua" )
else