Hi,
This is because global and local scopes. Is common feature in most programming languages.
You have defined num at the begginning of the code with export (int) var num
... it is defined "globally" and you can use it inside every function of your script. So, when you change its value with num = 5
you are changing the value of that global value, and it won't change again unless you explicity change it with another assignation like num = 1
.
However, in the second way, when you use var num = 5
You are NOT using the global variable, you are defining a new variable with the same name inside the local scope of the function _process
(var is used to define variables). So when you do var num = 5
you get a new variable named num with value of 5, different from global variable num. Inside _process
when you use num, you will be using local variable instead of global variable. But when you exit _process
function, local variables are removed, and you only keep your global variable with its original value. So when you stop pressing the button, the next time you enter process you wont be difining the local variable and you will be accessing global variable.
I don't know if i made myself clear, please tell me if you don't understand.