Lua函数的连接

时间:2012-08-03 16:54:22

标签: function lua concatenation

我试图通过使用Lua来连接一个函数,因为它实际上是一个玩家名字的变量。游戏再一次是命令与征服:Renegade。

错误是: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

1 个答案:

答案 0 :(得分:2)

错误在于您如何调用WriteINI。你在打电话

WriteINI(a,b,c,Get_Player_Name_By_ID)

而你应该打电话

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