ID:2180047
 
(See the best response by FKI.)
Code:
mob
player
proc
test()
var/x1 = 5
//...
x1 = 6
world << "[x1]"


Problem description: I have a variable x1 of a function test() with an initial value of 5. Somewhere in my code I want to make that variable have a value of 6, permanently everytime the function it is called. But the above code keeps printing 5. How can I fix its scope?
Thanks

You could make it a global variable (and constant, since you mentioned having it be permanent):

var const/x1 = 6

mob/player/proc/Test()
world << x1 // Always 6.

mob/player/proc/Test2()
world << x1 // Also 6.

Best response
The static keyword is also an option:

mob/player
proc/test()
var/static/x1 = 5
// ...
x1 = 6


The second time test() is called, x1 is still 6.
Probably not the best way to solve this problem but, you could try putting a sleep(1) before the output. That way the variable should have more then enough time to switch before outputting.

mob
player
proc
test()
var/x1 = 5
//...
x1 = 6
sleep(1)
world << "[x1]"