2013-07-12 2 views
3

나는 실패했을 때 프로그램의 상태를 백업하기 위해 모든 프로그램에 자주 쓰는 backup.lua라는 파일을 가지고있다. 문제는 프로그램이 backup.lua 파일을 처음부터 완벽하게 기록하지만 파일을 쓰지 못하게하는 경우입니다.닫힌 파일을 여는 중 :

프로그램이 열린 상태에서 파일을 제거하려고 시도했지만 프로그램에서 'CrysisWarsDedicatedServer.exe'파일이 사용 중이라고 나와 있습니다. 나는 호스트 Lua 함수에게 backup.lua 파일을 닫으라고 말했 읍니다. 그래서 닫혀진 후 파일을 수정할 수있게 해주지 않는 이유는 무엇입니까?

인터넷에서 아무것도 찾을 수 없습니다 (Google은 실제로 내 검색을 수정하려고 시도했습니다). 프로젝트의 보조 프로그래머도 알지 못합니다. 여러분 중 누군가 우리가 여기서 잘못하고있는 것을 알고 있는지 궁금합니다.

호스트 기능 코드 :

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 

모두 감사합니다 :).

편집 : 파일이 현재 디스크 벌금에 기록됩니다

있지만, 시스템이 덤프 파일을 읽는 데 실패합니다. 나는 심령니까

, 난 당신이 Crysis 플러그인을 작성하고 있으며, 시도하는 것을 점쳐왔다 :

답변

2

그래서, 지금 문제는 "LoadScript"기능은 당신이 기대하는 일을되지 않는 것입니다 LoadScript API call을 사용하십시오.

(이 추측 것, 또는 그것을 찾기 위해 방해 여기 모든 사람을 가정하지 마십시오 그것은 당신의 질문의 일부를 구성해야한다 중요한 정보입니다.)

당신이 Backup를 설정하는 시도를 작성하는 스크립트 - 그러나 스크립트는 작성된대로 줄 바꿈 문자로 줄을 구분하지 않습니다. 첫 번째 줄은 주석이므로 전체 스크립트는 무시됩니다.

기본 사항 작성한 스크립트는 다음과 같이 표시되며 모두 주석으로 처리됩니다.

--[[ comment ]]--Backup="Hello!" 

당신은 코멘트 후 "\ n을"을 작성해야합니다 (그리고, 나도 다른 장소에서 권 해드립니다)는 다음과 같이 만들 수 있습니다. 실제로 블록 주석이 전혀 필요하지 않습니다.

-- comment 
Backup="Hello!" 
+0

나는 Script.LoadScript가 글로벌 루아 기능이라고 생각했지만, 잘못된 것으로 입증되었습니다. :). 이것은 효과가 있습니다. 왜냐하면 24 시간을 기다려야하기 때문에 현상금을 수여 할 수는 없지만 제가 할 수있을 때 수여 할 것입니다. :). – cybermonkey

관련 문제