0
我有點卡住搞清楚爲什麼這不起作用。我沒有做任何代碼,所以我有點好奇爲什麼它不會工作。任何幫助表示讚賞。下面是錯誤的即時得到:嘗試索引全局'GameDatabase'(一個無值) - (一個Garrysmod腳本)
[ERROR] gamemodes/harborrp/gamemode/data.lua:59: attempt to index global 'GameDatabase' (a nil value)
1. Query - gamemodes/harborrp/gamemode/data.lua:59
2. unknown - gamemodes/harborrp/gamemode/sv_gamemode_functions.lua:790
3. UniqueID - [C]:-1
4. echoToAdmins - addons/ulx/lua/ulx/log.lua:164
5. fn - addons/ulx/lua/ulx/log.lua:202
6. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
[ERROR] gamemodes/harborrp/gamemode/data.lua:158: attempt to index global 'GameDatabase' (a nil value)
1. QueryValue - gamemodes/harborrp/gamemode/data.lua:158
2. LoadInventory - gamemodes/harborrp/gamemode/inventory/sv_inventory.lua:41
3. fn - gamemodes/harborrp/gamemode/inventory/sv_inventory.lua:58
4. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
[ERROR] gamemodes/harborrp/gamemode/data.lua:158: attempt to index global 'GameDatabase' (a nil value)
1. QueryValue - gamemodes/harborrp/gamemode/data.lua:158
2. unknown - gamemodes/harborrp/gamemode/sv_gamemode_functions.lua:1068
這裏的是它指的位置:
行58:
function DB.Query(query, callback, qtype)
local cBackFunc = function(r)
if r[1].error then
local err = table.concat({"tMySQL query error: ", r[1].error, debug.Trace() or "", "Query: ", query, "\n"}, "")
DB.Log(err)
ErrorNoHalt(err)
r[1].data = nil
//return
end
// lua_run DB.Query("SELECT amount, steam, rpname FROM metrorp_wallets limit 3", PrintTable, 1)
if callback then
if qtype == 0 then
ErrorNoHalt("Query "..query.." used Type 0 in DB.Query!\n")
local tbl = {}
for i=1, #r[1].data do
local ind = 1
tbl[i] = {}
for a,b in pairs(r[1].data[i]) do
tbl[i][ind] = b
ind = ind + 1
end
end
callback(tbl, !r[1].error)
else
callback(r[1].data, !r[1].error)
end
end
end
GameDatabase:Query(query, cBackFunc)
末
行158:
function DB.QueryValue(query, callback)
local function cBack(r)
if !r or !r[1].data or !r[1].data[1] then
callback(nil, !r[1].error)
return
end
local ind = next(r[1].data[1])
callback(r[1].data[1][ind], !r[1].error)
end
GameDatabase:Query(query, callback and cBack)
結束