Some event parameters being nil

Hello,

It seems that there is a bug with event parameters becoming nil when sent to a client.

Client : Production & canary
Server : 4980
2372

Here is a way to reproduce it :

Client side code :

RegisterNetEvent('test')
AddEventHandler('test', function(one, two, three, four, five, six, seven, eight)
    print(one, two, three, four, five, six, seven, eight)
end)

Server side code :

TriggerClientEvent('test', 1, 'one', 'two', 'three', nil, 'bubble', nil, nil, nil)

I would expect to see
one two three nil bubble nil nil nil
But instead I get

It looks like it happens only with those specific parameters. For exemple, if you remove the last nil at the end, it works as expected :

TriggerClientEvent('test', 1, 'one', 'two', 'three', nil, 'bubble', nil, nil)

prints

Thank you

after you hit the first nil in lua when sending server → client all other parameters will be nil.

While not a solution, just an explanation of the issue.

No, as explained in my post it’s not the case.
I think that some time ago there was a change to support nil parameters to avoid what you are talking about, and it works in most of the cases. (https://forum.cfx.re/t/event-argument-turns-into-nil-if-2-previous-were-nil/3937246)

In the case explained in my initial post, because of the specific order of parameters, some transform to nil.
The last example illustrate that even thought there is a ‘nil’ parameter in the middle of ‘three’ and ‘bubble’, the string ‘bubble’ is still there.

This is not solely server → client.

Edited
I ran a bunch of convoluted tests, but it’s all irrelevant after the final conclusion.


Lua is strange, this isn’t specific to FiveM / Cfx Lua.
image


When there are nil values in the table it will return some seemingly indeterminate number for the length, and if it’s the correct value then table.unpack will work and you receive the right arguments.