@vitserp You can make a local variable global while writing the program, as far as I know you can't do that once the program has started. Making a local variable global is very easy, you just move the declaration of the variable from inside a function to the beginning of your program. myvar in this example is local: void setup() { int myvar = 3; } and here it's global: int myvar; void setup() { myvar = 3; }
@vitserp Even you can't change the type of a variable once the program is running, you can copy the value of a local variable into a global variable and the other way around. For example: int myglobalvar = 3; void setup() { int mylocalvar = 77; myglobalvar = mylocalvar; } This way the variable myglobalvar will have a value of 77. You can access myglobalvar from inside any function in your program (setup(), draw(), mousePressed(), ...)
and how to make local variable to global ?
vitserp 3 months ago
@vitserp You can make a local variable global while writing the program, as far as I know you can't do that once the program has started. Making a local variable global is very easy, you just move the declaration of the variable from inside a function to the beginning of your program. myvar in this example is local: void setup() { int myvar = 3; } and here it's global: int myvar; void setup() { myvar = 3; }
hamoid 3 months ago
@vitserp Even you can't change the type of a variable once the program is running, you can copy the value of a local variable into a global variable and the other way around. For example: int myglobalvar = 3; void setup() { int mylocalvar = 77; myglobalvar = mylocalvar; } This way the variable myglobalvar will have a value of 77. You can access myglobalvar from inside any function in your program (setup(), draw(), mousePressed(), ...)
hamoid 3 months ago
@hamoid thanks good explanation :)
vitserp 3 months ago
congratulations for your 50th video, a great (and big) work!
gumli 5 months ago
@gumli Thank you! :)
hamoid 5 months ago