Lua (And SQL) Error, attempt to call a boolean value

所以我在为Garry的mod制作一个插件时遇到了这个错误,我已经尝试了一段时间,但是还没有完全搞清楚这个错误:

> [ERROR] addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6: attempt to call a boolean value > 1. loadcompany - addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6 > 2. unknown - addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:20 > 3. unknown - lua/includes/modules/concommand.lua:54

完整的文件已包含在内,因此行号将是精确的,因为我现在无法弄清楚这个格式,所以在pastebin上执行。 代码有点混乱,我已经有一段时间没有碰过这个问题,文件中的一半东西都会被替换掉。

include("stockmarketprices.lua")
include("stockmarket_config.lua")

local function loadcompany(cmp)

if cmp != nil and sql.TableExists("stockmarket_sharedata") then sql.Query("INSERT INTO stockmarket_sharedata (Companyshort, Company, Shares, Value) VALUES ('"..cmp[2]..", "..cmp[3]..", "..cmp[4]..", \"..cmp[5])\"")

end
end

local function test()

    if !sql.TableExists(stockmarket_sharedata) then
        print("股票市场执行初始加载...")
        sql.Query( "CREATE TABLE stockmarket_sharedata ( Companyshort string not null, Company string not null, Shares string not null, Value int not null, Rate decimal not null)" )

        print("股票市场加载完成,请重新启动服务器以应用更改。")
    end
    if stock1[1] == 1 then loadcompany(stock1)
        print(stock1[3].."已经加载完毕!")
        end
end
hook.Add("Initialize", "First Load", test)

function sharepricechange(shortname, chance, low, high, direction)
if math.random(1, 100) <= chance then shortname.marketbump = math.random(low, high) end

end

hook.Add( "PlayerSay", "chatcommands", function( ply, text )
    local text = string.lower( text )
    local amount = tonumber(string.sub(text, 16))
    local shares = tonumber(file.Read("stockmarket/lifeinsuranceshrs.txt"))

        if  string.sub(text, 1, 14) == "/buyshares ins" and amount <= shares then
            file.Write("stockmarket/lifeinsuranceshrs.txt", ((tonumber(file.Read("stockmarket/lifeinsuranceshrs.txt"))) - tonumber(string.sub(text, 16))))
            print("你已经投入!现在还有"..file.Read("stockmarket/lifeinsuranceshrs.txt").. "股份保险")
        else end

        if text == "/stockmarkethelp" then
            ply:PrintMessage(HUD_PRINTCONSOLE, [[ /buyshares "company" "amount" - 从指定的公司购买指定数量的股票。
            /stockmarket - 打印有关股票市场的所有信息。]])
        return("") end

end)

function ResetStockmarket(ply)
if ply:IsUserGroup("superadmin") then
local files, directories = file.Find( "*", "DATA")
print(files[1])
file.Delete("stockmarket")end
if !ply:IsUserGroup("superadmin") then ply:PrintMessage( HUD_PRINTCONSOLE, "您没有正确的权限使用此命令" )
end
end

concommand.Add( "stockmarket_reset", ResetStockmarket)
concommand.Add( "stockmarket_test", test)

pastebin.com/ERFfnbMc

stock1 = { -- DO NOT CHANGE THE TABLE IDENTIFIER
1, -- 第一行,确定是否要使该公司工作
"FLN", -- 公司的简称,保持三个字母的一致性
"弗林的葬礼", -- 公司的名称
10000, -- 默认的股票量
94, -- 每股的起始价格
0 -- 股票价值变化的速率,请不要触摸这些。
}

pastebin.com/jbJseUWC

点赞