简体   繁体   中英

attempt to call a nil value (upvalue 'successCB')

Hello i have a problem and it says attempt to call a nil value (upvalue 'successCB') i have tried different methods but didn't work so i want to know if you guys could help me

Here is the a picture of error

and here is main.lua:20

RegisterNUICallback("main", function(data)
    SetNuiFocus(false, false)
    QBCore.Functions.Notify("Authorization Success" , 'success', 7500)
    successCb()
end)

below also is a short part of the code JS code

    $("#submit").click(function () {
        let inputValue = $("#input").val()
        if (inputValue.length > 4) {
            $.post("http://vny-lvaultcodes/error", JSON.stringify({
                error: "Code cannot be greater than 4"
            }))
            $("#container").fadeOut(250);
            return
        } else if (!inputValue) {
            $.post("http://vny-lvaultcodes/error", JSON.stringify({
                error: "You need to type a 4 digit code for submitting."
            }))
            $("#container").fadeOut(250);
            return
        }
        if(inputValue == code){
            $.post('http://vny-lvaultcodes/main', JSON.stringify({text: inputValue,}));
            $("#container").fadeOut(250);
        } else {
            $.post('http://vny-lvaultcodes/failed', JSON.stringify({}));
            $("#container").fadeOut(250);


        }

also below it is a function to open the ui and stuff

function openCode(show, code, success, fail)
    successCb = success
    failCb = fail
    display = true
    SetNuiFocus(true, true)
    SendNUIMessage({
        type = "open",
        code = code,
    })
end

I'm unfamiliar with fivem but looking at the documentation, I think you've defined your callback incorrectly.

https://docs.fivem.net/docs/scripting-manual/nui-development/nui-callbacks/

RegisterNUICallback not only takes a data value but the callback as well (cb in the document).

In your case successCb would be nil thus when you call successCb() it produces the error.

As such, I'd try one of the following:

RegisterNUICallback("main", function(data, successCb)
    SetNuiFocus(false, false)
    QBCore.Functions.Notify("Authorization Success" , 'success', 7500)
    successCb()
end)
RegisterNUICallback("main", function(data, cb)
    SetNuiFocus(false, false)
    QBCore.Functions.Notify("Authorization Success" , 'success', 7500)
    cb()
end)

Hopefully that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM