Hello everyone,
I recently started trying to use nui for my resources I tried to use the nui callback and well it failed I tried to make a nui bill the displaying was ok everything worked but when I tried to use the buttons (I added the option to Decline or accept it) it done jack in good terms so said anyway the short version is it should return the value of what button I pressed (They are either “declined” or “accepted”)
it should work but it doesn’t does anyone got a idea how to fix it?
The reason returning isn’t working would be because you arent returning in the correct function. If you really want to return in that way, then something more like this would be what you want:
function CallBack()
local prom = promise.new()
RegisterNUICallback('response', function(data, cb)
cb('ok')
prom:resolve(data.action)
end)
Citizen.Await(prom)
return prom.value
end
local result = CallBack()
print(result)
Although in my opinion, handling nui callbacks in such way would really not be ideal.
Hello thanks for the reply I tried it but sadly it didn’t worked I override the CallBack function with the code you gave me and added the result
OpenBillPage(plate, buyPrice, km, lostWorth, taxes, finalPrice)
result = CallBack()
local reuslt = CallBack()
print(result)
(It is inside a script I need it for like accepting the deal for selling the vehicle) the nui page outputs the whole time it sends the response but I don’t receive any on the client side
I would recommend that you just register the nui callback normally it would be both easier and more readable. + There is no real need nor reason for why you would need to do it that way.
You are overcomplicating it quite a lot by trying to use an callback inside a callback.