From 9f830fd768c8dd2003ebb722fe57cbbd9c35e7d0 Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Wed, 20 Jan 2016 20:53:44 +0100 Subject: [PATCH] Updated errors when LFS is nil Statfile should not be used when lfs is null. Also, modified Moose.lua to the correct directory. --- Moose/Database.lua | 32 +++++++++++++++++++------------- Moose/Moose.lua | 6 +++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Moose/Database.lua b/Moose/Database.lua index 86d1c4a12..986896a78 100644 --- a/Moose/Database.lua +++ b/Moose/Database.lua @@ -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() diff --git a/Moose/Moose.lua b/Moose/Moose.lua index 4fd987e48..edacba13a 100644 --- a/Moose/Moose.lua +++ b/Moose/Moose.lua @@ -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