#applyDefaults。Boolean value (nil)

1 messages · Page 1 of 1 (latest)

quasi ginkgo
#
local function applyDefaults(playerData, defaults)
    for key, value in pairs(defaults) do
        if type(value) == 'function' then
            playerData[key] = playerData[key] or value()
        elseif type(value) == 'table' then
            playerData[key] = playerData[key] or {}
            applyDefaults(playerData[key], value)
        else
            playerData[key] = playerData[key] or value
        end
    end
end

`The above is the original applyDefaults.

If the SQL player's playermetadata data is a Boolean value,

The old code will treat the Boolean value as nil, causing a server restart to reload the original player data to the default values.

qb-core/config.lua - QBConfig.Player.PlayerDefaults`

Here is my repaired version

local function applyDefaults(playerData, defaults)
    for key, value in pairs(defaults) do
        if playerData[key] == nil then
            if type(value) == 'function' then
                playerData[key] = value()
            elseif type(value) == 'table' then
                playerData[key] = {}
                applyDefaults(playerData[key], value)
            else
                playerData[key] = value
            end
        elseif type(value) == 'table' and type(playerData[key]) == 'table' then
            applyDefaults(playerData[key], value)
        end
    end
end
sweet oar
#

is this a snippet or are you asking for support?

quasi ginkgo
#

But I am confused.
Why am I the only one who found this problem?

This is bound to happen.

open isle
#

This is for #1396805644337545236

#

If you think there's an issue you can use #1326383721930166292 or do a #📝┊public-prs

quasi ginkgo
open isle
quasi ginkgo
#

i'm very soory