num
is in global scope (note that the same behavior applies in e.g. Python)
If necessary, you could modify it by referencing as a global:
function getNum()
global num = 1
end
However, it is worth considering whether there is a more effective way to structure your code. Global variables can be useful in some situations, but they can also make code more difficult to reason about.