Hi Dark,
I think the concept you are missing here is called scope. Variables
can be declared in the local scope or the global scope. There are
important differences and uses of each of these types of variables.
Global variables are generally declared at the top of your
program/script and are visable to every function and variable in your
program. Since these types of variables generally remain in memory
from the time you start it to the time it ends you want to use global
variables sparingly. Only use them for data that needs to remain in
memory at all times such as a player's health, ammo remaining, etc.
Local variables are variables declared inside a function which belong
specifically to that function. When that function exits the variable
and the data it contains is destroyed. Since it is specific to that
function other functions and variables elsewhere in your program can't
access them directly. This is where return types come in handy. A
function can return the data stored in a local variable making local
variables accessible to other functions and variables as needed. Here
is a case in point.

int Add (int x, int y)
   return x+y;

void main ()
   int result = Add (5, 7);
   alert ("results", result);

In this simple script I created a function which adds two numbers. The
variables x and y are local, specific to the add function. I don't
really want the values stored in x and y, but only the result of x+y.
Add returns an integer value which is the sum of x and y. and passes
it to the result variable in main(). Does that make sense?
As for changing global variables you can change the value stored in it
anywhere in your program including the same function multiple times.
You don't have to create new functions just to reset health or
whatever back to 100.


On 3/24/10, dark <d...@xgam.org> wrote:
> I follow the printing business, ---- but I'm uncertain as to the "int first,
> int second business, sinse these don't seem to have been defigned, ---- also
> I'm a litle confused as to what a return statement is exactly for.
> I thought you make global variables and had your functions alter those.
> For instance, you start with int hp = 100. You setup a function to change
> this value, ---- then is it not changed until you setup another function to
> return it to 100 again?
> Beware the grue!
> Dark.

Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
All messages are archived and can be searched and read at
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to