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...
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:
function MyFunction(int par)
{
par=1;
return par;
}
and then call it like so:
int X;
//later...
x = MyFunction(X);
This is all pretty basic stuff and works almost exactly as in C/C++
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?
Have you exported & imported it properly?
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.