Lua(和SQL)错误,尝试调用布尔值

Lua(和SQL)错误,尝试调用布尔值,sql,lua,garrys-mod,Sql,Lua,Garrys Mod,因此,我在为Garrys mod制作插件时遇到了这个错误,我已经尝试了一段时间,但无法完全理解这个错误: [错误]加载项/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6:尝试调用布尔值 1.loadcompany-addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6 2.未知-addons/ted_stockmarket/lua/autorun/serv

因此,我在为Garrys mod制作插件时遇到了这个错误,我已经尝试了一段时间,但无法完全理解这个错误:

[错误]加载项/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6:尝试调用布尔值 1.loadcompany-addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:6 2.未知-addons/ted_stockmarket/lua/autorun/server/stockmarket_init.lua:20 3.未知-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("Stock market performing initial load...")
        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("Stock market done loading, restart your server to apply changes.")
    end
    if stock1[1] == 1 then loadcompany(stock1)
        print(stock1[3].." is done loading!")
        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("You have invested! There are now "..file.Read("stockmarket/lifeinsuranceshrs.txt").. " shares left for life insurance")
        else end

        if text == "/stockmarkethelp" then
            ply:PrintMessage(HUD_PRINTCONSOLE, [[ /buyshares "company" "amount" - Purchase a specified amount of shares from a specified company.
            /stockmarket - Prints all information about the stock market in console.]])
        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, "You are not the right rank to use this command" )
end
end

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

pastebin.com/jbJseUWC

您在语法方面有一些问题。Lua的“不相等”运算符写为
~=
,而不是
=。此外,布尔否定表示为运算符
not
,并且在函数调用前不带感叹号。首先修复这些。@Vlad-garrys mod用增强的语法修改了Lua。是的,感叹号表示布尔否定。啊,不知道语法中添加了哪些内容……Lua和SQL都不正确:将
值(“.cmp[2]”、“.cmp[3]”、“.cmp[4]”、“.cmp[5]”)替换为
值(“.cmp[2]”、“.cmp[3]”、“.cmp[4]”、“.cmp[5]”)。弗林的葬礼
应该有内部的
'
以某种方式逃脱(可能是通过加倍?使用
cmp[3]:gsub(“,”)
加倍)请不要使用pastebin,只需在你的问题中添加你的代码即可。
stock1 = { -- DO NOT CHANGE THE TABLE IDENTIFIER
1, -- First line, determine whether or not you want this company to work
"FLN", -- The shortname of the company, keep 3 letters for consistency
"Flynn's Funerals", -- The name of the company
10000, -- The default amount of shares avaliable
94, -- The starting price of each share
0 -- The rate of the shares change in value, do not touch this.
}