我有一个名为backup.lua的文件,程序应该每隔一段时间写一次,以便在出现故障时备份其状态。 问题在于程序首次将backup.lua文件写入完全正确,但是在其他任何时候拒绝写入文件。
我试图删除文件,而程序仍然打开,但Windows告诉我,该文件正在使用'CrysisWarsDedicatedServer.exe',这是该程序。 我已经告诉主机Lua函数closures了backup.lua文件,那为什么不让我在closures之后随意修改这个文件呢?
我在互联网上找不到任何东西(Google实际上试图纠正我的search),项目的二级程序员也不知道。 所以我想知道你们中的任何一个人是否知道我们在这里做错了什么?
主机function码:
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
感谢所有:)。
编辑:
尽pipe文件现在已经写入磁盘,但系统却无法读取转储的文件。
所以,现在的问题是,“LoadScript”函数没有做你期望的:
因为我是精神病患者,所以我已经知道你正在编写一个Crysis插件,并试图使用它的LoadScript API调用 。
(请不要以为这里的每个人都会猜到这个,或者不屑于寻找它,这些重要的信息必须构成你的问题的一部分)
您正在编写的脚本尝试设置Backup
– 但是您的脚本,如书面 – 不会将行与换行符分开。 由于第一行是注释,整个脚本将被忽略。
Basicallty你写的脚本看起来像这样,这是作为一个评论。
--[[ comment ]]--Backup="Hello!"
你需要在评论之后写一个“\ n”(并且,我也会在其他地方推荐)来做这个。 事实上,你根本不需要阻止评论。
-- comment Backup="Hello!"