NetworkGetNetworkIdFromEntity and other entity natives error in usage with pcall
What happened?
They throw errors AND HALT code even when called with pcall which should suppress errors.
Expected result
Don't halt code
Reproduction steps
print(pcall(NetworkGetNetworkIdFromEntity(1))) print(NetworkGetNetworkIdFromEntity(1))
Importancy
Unknown
Area(s)
FiveM
Specific version(s)
FiveM
Additional information
No response
Also they throw errors without a proper stacktrace.
It throws an error because you are calling it incorrectly.
print(pcall(NetworkGetNetworkIdFromEntity(1)))
Written like this, NetworkGetNetworkIdFromEntity(1) is executed before the pcall call. Then pcall receives its return value and tries to run using that, but the first parameter of pcall must be a function reference so that pcall itself can call it and handle any errors. After that, you list the function’s arguments without calling the function, like this:
pcall(NetworkGetNetworkIdFromEntity, 1)