I'm currently fiddling around with a project that has its code divided among multiple script modules. There's two structs being used in the project and each struct has its own script module. Things kinda look like this:
Module with struct 1 header:
Code: ags
Module with struct 1 script:
Code: ags
Module with struct 2 header:
Code: ags
Module with struct 2 script:
Code: ags
In the "room_load" section of the starting room, the following code is executed:
Code: ags
Now there's a function I'd like to use that uses data from both structs looking something like this:
Code: ags
This function works fine in the room code, but when I tried putting it in a separate module (I wanted to create one specifically for all misc functions that use data from both structs), things malfunction. The misc-module is placed beneath the two struct-modules, so it can see the public variables of both structs just fine. However, the function when placed in the misc module always returns true and when looking at the values it retrieves, the only results were straight 0's for all ID-vars in both structs as if the init-process never took place. Any idea on how to fix this?
Module with struct 1 header:
struct Apple
{
int ID;
import int Init(int index);
};
Apple Apples[10];
Module with struct 1 script:
function Apple::Init(int index)
{
this.ID=index;
}
Module with struct 2 header:
struct Orange
{
int ID;
import int Init(int index);
};
Orange Oranges[10];
Module with struct 2 script:
function Orange::Init(int index)
{
this.ID=index*2;
}
In the "room_load" section of the starting room, the following code is executed:
int i=0;
while (i<10)
{
Apples[i].Init(i);
Oranges[i].Init(i);
i++;
}
Now there's a function I'd like to use that uses data from both structs looking something like this:
function Compare(int applenr, int orangenr)
{
if (Apples[applenr].ID==Oranges[orangenr].ID) return true;
else return false;
}
This function works fine in the room code, but when I tried putting it in a separate module (I wanted to create one specifically for all misc functions that use data from both structs), things malfunction. The misc-module is placed beneath the two struct-modules, so it can see the public variables of both structs just fine. However, the function when placed in the misc module always returns true and when looking at the values it retrieves, the only results were straight 0's for all ID-vars in both structs as if the init-process never took place. Any idea on how to fix this?
