• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
split pawn codes
#2
Well off course! And you absolutely should do that! You're also already doing it in fact when including includes.. Thus use #include to include different files.

#include <someInclude> would attempt to include "PATH_TO_INCLUDES_DIRECTORY/someInclude.inc"

#include "someInclude.inc" or #include "someInclude" would attempt to include "PATH_RELATIVE_FILE/someInclude.inc" (you could use different extensions. Eg. gamemode sf-cnr uses .pwn for all includes -- don't, though. ".inc" is the correct file extension)



For example:



./gamemodes/gamemode.pwn



Code:
#include <a_samp>



#include "src/assembly.inc"



public OnGameModeInit()

{

??? print("Final OnGameModeInit() call!");

??? return 1;

}



./gamemodes/src/assembly.inc

Code:
#include "src/init.inc"

#include "src/server/mysql.inc"



./gamemodes/src/init.inc

Code:
#include <YSI_Coding\y_hooks>



hook OnGameModeInit()

{

??? print("First OnGameModeInit() call! Start loading gamemode");

?? return 1;

}



./gamemodes/src/server/mysql.inc

Code:
#include <YSI_Coding\y_hooks>



hook OnGameModeInit()

{

??? print("Second OnGameModeInit() call! Setting up MySQL connection");

??? return 1;

}

Etc..



There are probably 'rules' around as how to name files (eg. using 'header.inc' and 'impl.inc' files) but I'm too noob for that :-)

Here are a few gamemodes that do use multiple files in case you need examples.?

https://github.com/PatrickGTR/gta-open

https://github.com/MaxAndolini/NG-RP

https://github.com/zeelorenc/sf-cnr



Ultimately this will all be combined into one file (by the pre-processor) - including the plugins. It has no effect on the performance of the server.

If you're curious and want to see that for yourself, compile with option "-l" (either put #pragma option -l in your script (do use the latest compiler) or append it to pawncc args).

This will show the output of the stage after the pre-processor's output and before compiling it to assembler code/binary file (amx) in a .asm file. This for example (note that this doesn't make much sense):



./script.pwn

Code:
#include "myInclude.inc"



#pragma option -l



#define MY_CONSTANT 5



main()

{

??? print("MY_CONSTANT IS "#MY_CONSTANT);

}



./myInclude.inc

Code:
native print(const string[]);

Would output something like this: (without "#file" and "#line" outputs: when using -l it adds that to the script to show what's where)

Code:
native print(const string[]);



main()

{

??? print("MY_CONSTANT IS "#5);

}
  Reply


Messages In This Thread
split pawn codes - by redex - 2021-07-28, 03:46 PM
RE: split pawn codes - by Kwarde - 2021-07-28, 06:57 PM
RE: split pawn codes - by Pinch - 2021-07-28, 07:48 PM
RE: split pawn codes - by redex - 2021-07-29, 10:21 AM

Forum Jump: