Markx Posted October 17, 2020 Share Posted October 17, 2020 Hello, I would like to know if there is any difference between using addEventHandler in these 2 ways as shown below: A: local list = { {-2172.03833, -2286.10107, 29.63500, 1.75}, } addEventHandler("onResourceStart", resourceRoot, function () for i, v in ipairs(list) do local Mark = createMarker(v[1], v[2], v[3], "cylinder", v[4], 255, 255, 255, 50) end end) B: local list = { {-2172.03833, -2286.10107, 29.63500, 1.75}, } function create() for i, v in ipairs(list) do local Mark = createMarker(v[1], v[2], v[3], "cylinder", v[4], 255, 255, 255, 50) end end addEventHandler("onResourceStart", resourceRoot, create) In the first example (A) I can make it work in the MTA, but in the second example it doesn't seem to work and I get the following error: stack overflow. Could someone tell me what the difference is between using addEventHandler before the function and after? and why In the second example (B) am I getting an error? I would be grateful for the help, thank you. Link to comment
Administrators Tut Posted October 17, 2020 Administrators Share Posted October 17, 2020 Your thread has been moved to the Scripting forum for the best results. Link to comment
Scripting Moderators ds1-e Posted October 17, 2020 Scripting Moderators Share Posted October 17, 2020 2 hours ago, Markx said: and why In the second example (B) am I getting an error? Second example works fine, i've just tested it. About differences: - Example A register event with anonymous function. - Example B register event with non-anonymous function. How does it affect your code? Considering that you would want to remove this event handler, it will be not possible in A example (probably possible with searching _G). And for me it looks awful. So i prefer using B way over A. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now