-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unintuitive scripting behavior: source variable in Lua becomes nil if any time passes during event handler #1502
Comments
It's not bug, the source variable is defined in scheduler.lua as global variable fivem/data/shared/citizen/scripting/lua/scheduler.lua Lines 156 to 159 in 71a593b
So, you can simply use: local src = source at top of event handler to use event source after wait |
Noted, i figured this was some weird behavior but seeing how that works now makes sense and any alternative would not be within the realm of easy fixing. Closing |
This is still somewhat illogical behavior, but somehow dynamically adding upvalues for a handler sounds like a potential mess (and requiring the lexer/parser to be aware of this beforehand, even). A similar alternative could be something like the .NET SynchronizationContext where state like 'source' is saved and restored when yielding with such set. |
When a server event handler is being run, the source variable thats inherently provided becomes nil if any time passes i.e Wait()'ing
This is confusing behavior and presumably not intended
it can be worked around by simply defining a second variable and setting it to the value of source at the beginning but is obviously not ideal
Repro code:
CLIENT:
SERVER:
The text was updated successfully, but these errors were encountered: