Need help with subs!!!
-
- Newbie
- Posts: 8
- Joined: Sat May 06, 2006 8:32 pm
Need help with subs!!!
I am making an RPG game that uses money, and I put the shops in a sub. I need a way to total the money i picked up in one sub or the main module and transfer it to the shop subs. So basically a way to transfer a variable from one sub to another.
What you've got to understand is the difference between a local variable and a global variable. When your program is all in one module, both types act the same, but when your program is broken up into a main module and subs, the difference becomes apparent.
Any variable used in either the main module or any of the subs is automatically a local variable. This means that only this section of the program can use the value of this variable. If you've got a variable like Gold=200 in your main program, and you try to say print Gold in one of your subs, the sub would print zero.
A global variable is one that all parts of the program recognize. You define these in your main module like this:
DIM SHARED Gold AS INTEGER
Now that the variable "Gold" is shared, you can assigning it a value in any part of your program, and any other part of your program can use that value.
Any variable used in either the main module or any of the subs is automatically a local variable. This means that only this section of the program can use the value of this variable. If you've got a variable like Gold=200 in your main program, and you try to say print Gold in one of your subs, the sub would print zero.
A global variable is one that all parts of the program recognize. You define these in your main module like this:
DIM SHARED Gold AS INTEGER
Now that the variable "Gold" is shared, you can assigning it a value in any part of your program, and any other part of your program can use that value.
Daniel "Theophage" Clark
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
theophage (at) geocities (dot) com
"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."