Mickoi Posted January 21, 2021 Posted January 21, 2021 Hi guys, i came to you with another question. For example, i have main_c.lua and utilities_c.lua and in main_c.lua i create onClientClick event and i need function 'isMouseIn' (check if mouse is in positions...) and i can do it by add code on top of main_c.lua at local function, but i attention when code is clear and i want to create this function in file utilities_c.lua and it will be global function so there is my question. Is that difference is big? local function and global function in other file? I hope you can read what i said! Thank you in advance.
Moderators IIYAMA Posted January 21, 2021 Moderators Posted January 21, 2021 1 hour ago, Mickoi said: local function and global function in other file? Function names are variables. local variables are only available within their block. local variables are faster in speed. (performance) Blocks: Local functions can't be called from another file. Local functions can't be called outside of: (other) Function if statement Loop etc. -- file 1 local function test () end -- -- file 2 iprint(test) -- nil -- if true then local function test () end end iprint(test) -- nil function something () local function test () end end iprint(test) -- nil Depending on how the function variable is defined: local function test () iprint(test) -- function... end local test = function () iprint(test) -- nil (The function is created, before the variable is available.) end iprint(test) -- Function... local test test = function () iprint(test) -- function... end Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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