Jump to content
  • Advertisement
Sign in to follow this  
Bow_vernon

"global" and "static" module

This topic is 1768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

You can use function imports to accomplish this.

 

In your "static" modules add the following:

 

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!