2012-08-03 79 views
1

我想通過使用Lua來連接一個函數,因爲它實際上是一個玩家的名字的變量。遊戲再次是命令與征服:叛徒。Lua中功能的連接

錯誤是:Attempt to concatenate local 'Value' (a function value)這發生在使用Get_Player_Name_By_ID,但是,我不知道任何方式使用,因爲我需要能夠確定哪個用戶有哪些killstreaks!此外,它發生在第210行左右。這在WriteINI函數中。

這裏是我的代碼:

function OnChat(pID, Type, Message, Target) 
FindWords(Message) 

if Message == "!killstreaks" then 
InputConsole("pamsg %d Killstreaks are a fundamental part of our server. You choose 3 killstreaks to be enabled for use, when you achieve a certain number of kills. Now type !select <Assault/Support>", pID) 
end 

if FirstW == "!select" or FirstW == "!choose" then 
    if SecondW == "Assault" or SecondW == "assault" then 
     InputConsole("pamsg %d Attack Chopper Strafe Run AH-6 Overwatch Reaper Assault Drone AC130 Pavelow Juggernaut Oseprey Gunner", pID) 
     InputConsole("pamsg %d UAV Care Package IMS Predator Missile Sentry Gun Precision Airstrike", pID) 
     InputConsole("pamsg %d Now type !ks1 <killstreak>, then !ks2 <killstreak>, then !ks3 <killstreak> with 3 of these killstreaks:", pID) 
      WriteINI("killstreaks.ini", "Choice", "Assault", Get_Player_Name_By_ID) 
    elseif SecondW == "Support" or SecondW == "support" then 
     InputConsole("pamsg %d EMP Juggernaut Recon Escort Airdrop", pID) 
     InputConsole("pamsg %d UAV Counter UAV Ballistic Vests Airdrop Trap SAM Turret Recon Drone Advanced UAV Remote Turret Stealth Bomber", pID) 
     InputConsole("pamsg %d Now type !ks1 <killstreak>, then !ks2 <killstreak>, then !ks3 <killstreak> with 3 of these killstreaks:", pID) 
      WriteINI("killstreaks.ini", "Choice", "Support", Get_Player_Name_By_ID) 
    end 
end 
return 1 
end 

function ReadINI(File, Section, KeyName) 

blnSection = false 
intAction = 0 
strBracket = [[[]] 

    if File ~= nil and Section ~= nil and KeyName ~= nil then 
     if File ~= "" and Section ~= "" and KeyName ~= "" then 
     i = io.open(File, "r") 
     if i ~= nil then 
      while true do 
       local Line = i:read() -- Reads a line 
       if Line == nil or intAction ~= 0 then 
        break 
       else 
        if blnSection == false then 
        Found = string.sub(Line, 0, 1) 
       if Found == strBracket then -- Found Header 
        Header = string.sub(Line, 2, -2) 
        if Header == Section then 
         blnSection = true 
        end 
       end 
       else 
       Header = string.sub(Line, 0, 1) 
       if Header == strBracket then 
        intAction = 2 
       elseif Header == ";" then 
        -- Ignor Comments 
       elseif Line == "" then 
        -- Ignor Blank Lines 
       else 
        strFindEqual = string.find(Line, "=") 
        if strFindEqual ~= nil then 
         strKeyname = string.sub(Line, 0, strFindEqual - 1) 
         if strKeyname == KeyName then 
          intAction = 1 
          Value = string.sub(Line, strFindEqual + 1) 
         end 
        end 
       end 
       end 
      end 
     end 

     i:close() 

     if intAction == 1 then 
      return Value 
     elseif intAction == 2 then 
      return NoneError 
     else 
      return NoneError 
     end 
    else 
     return FileError 
    end 
     else 
     return ArgError 
     end 
    else 
     return ArgError 
    end 
end 


function WriteINI(File, Section, KeyName, Value) 

    blnSection = false 
    intAction = 0 
    strBracket = [[[]] 
    strCloseBracket = [[].]] 
    strCloseBracket = string.sub(strCloseBracket, 1, 1) 
    Save = "" 

    if File ~= nil and Section ~= nil and KeyName ~= nil and Value ~= nil then 
     if File ~= "" and Section ~= "" and KeyName ~= "" and Value ~= "" then 
     i = io.open(File, "r") 
     if i ~= nil then 
     while true do 
      local Line = i:read() -- Reads a line 
      if Line == nil then 
       break 
      else 
       if intAction == 0 then 
       if blnSection == false then 
        Found = string.sub(Line, 0, 1) 
        if Found == strBracket then -- Found Header 
         Header = string.sub(Line, 2, -2) 
         if Header == Section then 
          blnSection = true 
         end 
        end 
       else 
        Header = string.sub(Line, 0, 1) 
        if Header == strBracket then 
         blnSection = false 
         Line = KeyName .. "=" .. Value .. "\n" .. Line 
         intAction = 1 
        elseif Header == ";" then 
         -- Ignor Comments 
        elseif Line == "" then 
         -- Ignor Blank Lines 
        else 
         strFindEqual = string.find(Line, "=") 
         if strFindEqual ~= nil then 
          strKeyname = string.sub(Line, 0, strFindEqual - 1) 
          if strKeyname == KeyName then 
          Line = KeyName .. "=" .. Value 
          intAction = 1 
          end 
         end 
        end 
       end 
       end 

       Save = Save .. Line .. "\n" 
      end 
     end 

     i:close() 

     if intAction ~= 1 then 
      if blnSection == false then 
       Save = Save .. strBracket .. Section .. strCloseBracket .. "\n" .. KeyName .. "=" .. Value 
      else 
       Save = Save .. KeyName .. "=" .. Value 
      end 
     end 

     i = io.open(File, "w") 
      i:write(Save) 
     i:close() 
    else 
     i = io.open(File, "w") 
      i:write(strBracket .. Section .. strCloseBracket .. "\n" .. KeyName .. "=" .. Value) 
     i:close() 
     end 
     else 
     return ArgError 
     end 
    else 
     return ArgError 
    end 
end 

function FindWords(Text) 

    Found = string.find(Text, " ") 
    if Found ~= nil then 
     FirstW = string.sub(Text, 0, Found - 1) 
     SecondW = string.sub(Text, Found + 1) 
     SecondPlus = SecondW 

     Found = string.find(SecondW, " ") 
     if Found ~= nil then 
    ThirdW = string.sub(SecondW, Found + 1) 
    SecondW = string.sub(SecondW, 0, Found - 1) 
    ThirdPlus = ThirdW 

    Found = string.find(ThirdW, " ") 
    if Found ~= nil then 
     FourthW = string.sub(ThirdW, Found + 1) 
     ThirdW = string.sub(ThirdW, 0, Found - 1) 

     Found = string.find(FourthW, " ") 
     if Found ~= nil then 
      FourthW = string.sub(FourthW, 0, Found - 1) 
     end 
    else 
     FourthW = "" 
    end 
    else 
    ThirdW = "" 
    ThirdPlus = "" 
    FourthW = "" 
    end 
    else 
    FirstW = Text 
    SecondW = "" 
    SecondPlus = "" 
    ThirdW = "" 
    ThirdPlus = "" 
    FourthW = "" 
    end 
end 
+0

嗯,只是想知道,如果我做了什麼Get_Player_Name_By_ID = 「%d」,然後使用 「%d」?編輯:不,那沒用。 – Talisman 2012-08-03 17:05:15

回答

2

的錯誤是你如何調用WriteINI。要調用

WriteINI(a,b,c,Get_Player_Name_By_ID) 

而你應該打電話

WriteINI(a,b,c,Get_Player_Name_By_ID(Player_ID)) 
+0

王牌!感謝您的快速回復!附:注意到您在「Lua」上的編輯不是縮寫! – Talisman 2012-08-03 17:36:17