【问题标题】:ROBLOX LUA(u) passing argument of table = nil (attempt to concatenate nil with string)ROBLOX LUA(u) 传递 table = nil 的参数(尝试将 nil 与字符串连接)
【发布时间】:2021-09-30 14:44:21
【问题描述】:

我正在尝试创建一个数据库,但仍处于测试阶段,但是: 正如你所看到的,它基本上是拆表给我们“nil”。

这是一个我无法修复的奇怪错误。

测试 ServerScriptService 脚本:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Greenwich = require(ServerStorage:WaitForChild("Greenwich"))

Players.PlayerAdded:Connect(function(Player)
    
    Player.Chatted:Connect(function(Message)
        
        if Message == "t" then
            
            local ServerName = script.Name
            print("T has been recognized by "..ServerName)
            
            print(Greenwich:GetDB("salvage"))
            warn(Greenwich:GetDB("salvage"):Set("MyKey", "MyValue"))
            
            print("Finalized.")
            
        end
        
    end)
    
end)

模块脚本:

--Variables
local dss = game:GetService("DataStoreService")
local db = dss:GetDataStore("greenwich")

-- Tables
local greenwich = {}
local dbFunctions = {}

--Functions
function greenwich:GetDB(name)
    local new = {}
    coroutine.resume(coroutine.create(function()
        for k, v in pairs(dbFunctions) do
            new[k] = function(...)
                local args = { ... }
                return v(name, unpack(args))
            end
        end
    end))
    return new
end

function dbFunctions:Set(save_key, key, value)
    save_key = unpack(save_key)
    db:SetAsync(
        save_key..
            key,
        value)
    return value
end

--Returning everything.
return greenwich

提前致谢。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    save_keynew是同一张表

    save_key = unpack(save_key)nil 分配给save_key

    unpack(save_key) 返回nil,因为save_key 不是一个序列。

    unpack (list [, i [, j]]) 等价于return list[i], list[i+1],..,list[j] 在哪里 ij 默认为 1#list

    new 中的唯一字段是new["Set"]

    【讨论】:

      猜你喜欢
      • 2021-04-26
      • 2021-07-04
      • 2021-09-29
      • 1970-01-01
      • 2013-11-29
      • 2013-06-04
      • 1970-01-01
      • 2021-09-23
      • 2020-12-16
      相关资源
      最近更新 更多