Different between local variables and self variable? (SOLVED)

in here, i ask you is local variables are important?

The different lexical scopes in Lua are described here: https://defold.com/manuals/lua/#locals-globals-and-lexical-scoping

And here: https://defold.com/manuals/script/#script-execution-callbacks-and-self

I will always make variables local unless I have a good reason to otherwise, such as making some functions globally available (even this we tend to keep them in a globals.lua which we require as needed). Sometimes storing information in self is useful, other times it is more useful to share data via a shared Lua module.

3 Likes