fodev.net

FOnline Development => Share Your Work => Topic started by: adumbperson on June 30, 2016, 02:50:09 pm

Title: How to write some AS modules
Post by: adumbperson on June 30, 2016, 02:50:09 pm
Write your constants into some module_name_h.fos
Code: [Select]
#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

write your module abstraction into some module_name.fos
Code: [Select]
#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] );
}


Now to use your module just add this to scripts.cfg
Code: [Select]
@ server module module_name
and to use it through your scripts
into client_main.fos as example
Code: [Select]
#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

You can also use __CLIENT/__SERVER constants
Code: [Select]
#ifdef __SERVER
// server side
#endif

#ifdef __CLIENT
// client side
#endif


That's all.