我有一个名为backup.lua的文件,程序应该每隔一段时间写一次文件以备份其状态,以防出现故障。 问题是该程序首次将backup.lua文件写入完全正确,但其他任何时候它拒绝写入该文件。重新打开关闭的文件:Lua
我试图在程序仍然打开时删除文件,但Windows告诉我文件正在被'CrysisWarsDedicatedServer.exe'使用,这是该程序。我已经告诉主机Lua函数关闭了backup.lua文件,为什么不让它在关闭后随意修改文件?
我在互联网上找不到任何东西(谷歌实际上试图纠正我的搜索),项目的辅助程序员也不知道。 所以我想知道你们中的任何一个人是否知道我们在这里做错了什么?
Host功能代码:
function ServerBackup(todo)
local write, read;
if todo=="write" then
write = true;
else
read = true;
end
if (write) then
local source = io.open(Root().."Mods/Infinity/System/Read/backup.lua", "w");
System.Log(TeamInstantAction:GetTeamScore(2).." for 2, and for 1: "..TeamInstantAction:GetTeamScore(1))
System.LogAlways("[System] Backing up serverdata to file 'backup.lua'");
source:write("--[[ The server is dependent on this file; editing it will lead to serious problems.If there is a problem with this file, please re-write it by accessing the backup system ingame.--]]");
source:write("Backup = {};Backup.Time = '"..os.date("%H:%M").."';Backup.Date = '"..os.date("%d/%m/%Y").."';");
source:write(XFormat("TeamInstantAction:SetTeamScore(2, %d);TeamInstantAction:SetTeamScore(1, %d);TeamInstantAction:UpdateScores();",TeamInstantAction:GetTeamScore(2), TeamInstantAction:GetTeamScore(1)));
source:close();
for i,player in pairs(g_gameRules.game:GetPlayers() or {}) do
if (IsModerator(player)) then
CMPlayer(player, "[!backup] Completed server backup.");
end
end
end
--local source = io.open(Root().."Mods/Infinity/System/Read/backup.lua", "r"); Can the file be open here and by the Lua scriptloader too?
if (read) then
System.LogAlways("[System] Restoring serverdata from file 'backup.lua'");
--source:close();
Backup = {};
Script.LoadScript(Root().."Mods/Infinity/System/Read/backup.lua");
if not Backup or #Backup < 1 then
System.LogAlways("[System] Error restoring serverdata from file 'backup.lua'");
end
end
end
感谢所有:)。
编辑:
尽管文件正在写入到磁盘精细,系统无法读取倾倒文件。
我以为Script.LoadScript是一个全球Lua功能,我已被证明是错误的:)。这工作 - 我现在不能奖励赏金,因为我必须等待24小时,但当我可以这样做时我会奖励它。 – cybermonkey