FOnline Development > Share Your Work

How to write some AS modules

(1/1)

adumbperson:
Write your constants into some module_name_h.fos

--- Code: ---#define ONE_THING (0)
#define TWO_THING (1)
#define THREE_THING (2)

// also write your IMPORT here
#ifdef _MODULE_NAME
import void superFuncDoingSuperStuff() from "module_name.fos";
#endif

--- End code ---

write your module abstraction into some module_name.fos

--- Code: ---#include "module_name_h.fos" // to have our previous declaration available

string@[] meh = {
"one_thing",
"two_thing",
"three_thing"
};

void superFuncDoingSuperStuff()
{
    Log("Sorry for my lazyness.\n" + meh[THREE_THING] );
}


--- End code ---

Now to use your module just add this to scripts.cfg

--- Code: ---@ server module module_name
--- End code ---

and to use it through your scripts
into client_main.fos as example

--- Code: ---#define _MODULE_NAME
#include "module_name_h.fos" // so the IMPORTS works here

// through some client_main.fos's function
#ifdef _MODULE_NAME // checks the availability
superFuncDoingSuperStuff(); // use if available
#endif

--- End code ---

You can also use __CLIENT/__SERVER constants

--- Code: ---#ifdef __SERVER
// server side
#endif

#ifdef __CLIENT
// client side
#endif

--- End code ---


That's all.

Navigation

[0] Message Index

Go to full version