Followers 0

# "global" and "static" module

## 3 posts in this topic

Hi all, I have a problem now. I design that in the game, I'll have one global module (that is where I store functions that another module can call), and many "static" module. I need the "static" module to be able to refer to the "global" module such as :

//global.as
//this is where I define a set of "default" function
void def_item_drop_behavior()
{
//do something generic
}

//sword.as

void on_drop()
{
//do something that is "sword" specific
blah();
//do something that every item would do when dropped
def_item_drop_behavior();
}

//potion.as

void on_drop()
{
//do something "potion" specific
blah();
//do something that every item would do when dropped
def_item_drop_behavior();
}


now I'm at lost at how I'm supposed to do this. Any insight?

EDIT : I'm using angelscript of course, I recently see the sample on the SDK. The #include sample basically, it allowed me to reuse code, but I don't want to duplicate variables. I need the variables in the "global" module to be shared/referenced by the other script. That's what I'm pursuing.

I'm rethinking my approach now, so feel free to give suggestions. Thanks a bunch!!

Edited by Bow_vernon
0

##### Share on other sites

Not sure what you are asking, but I'll take a shot.

Assuming this is actionscript, You probably need to read up on "package" and "import" commands.

Create a global package (global.as) , then import it in every module (sword.as)

0

##### Share on other sites

Not sure what you are asking, but I'll take a shot.

Assuming this is actionscript, You probably need to read up on "package" and "import" commands.

Create a global package (global.as) , then import it in every module (sword.as)

Its in the angelcode forum so its most likely AngelScript

0

##### Share on other sites

You can use function imports to accomplish this.

import void def_item_drop_behavior() from "global";


When the application compiles the "static" modules it must call the method BindAllImportedFunctions on the module after the build completes.

You may also want to read up on shared entities, with which you can share classes and interfaces between modules so you don't have to work with just primitives and registered types in the imported functions.

Regards,

Andreas

1

## Create an account

Register a new account