Public Variables

Started by , Fri 07/10/2005 02:44:57

Previous topic - Next topic

gounis

Hello guys...
Let's suppose that I have a public var "X" of type "int"  in my room script.
Also,suppose that I have a function MyFunction(int par) created with module manager.
When I parse "X" in MyFunction, I want to change the public value of "X", and not just the function's "X";

For example I have:
function MyFunction(int par)
{
    par=1;
}

and sometime I call this function from my room script: MyFunction(X);
I want the public value of X to be 1...but this-logically-doesn't happen.
With C++ I could do this with method reference:
function MyFunction(int *par)
{
    *par=1;
}

and when I called it: MyFunction(&X);
but this doesn't work...
Thanx in advance...

HeirOfNorton

AGS only supports pointers to built-in classes, so this won't work with other variables. The way to do it with the example you gave is by returning the new value, like so:

Code: ags

function MyFunction(int par)
{
    par=1;
    return par;
}


and then call it like so:

Code: ags

int X;

//later...

x = MyFunction(X);


This is all pretty basic stuff and works almost exactly as in C/C++

gounis

OK,I had this in mind...
Now,something else...
When I  declare a global variable in global script, why I cannot use it from the room script as I can do with global script's methods?

Ashen

Have you exported & imported it properly?
I know what you're thinking ... Don't think that.

Pumaman

Global variables, unlike functions, need to be exported from the global script.

Place a line like this:

export variablename;

at the end of the global script, where variablename is the variable to export.

SMF spam blocked by CleanTalk