Q: Scripting practice
#1

Hey everyone!
I was wondering if I make some includes, such as cmds.inc which contains the commands of the script, stocks would have its include too. Is that a good practice?
Reply
#2

Quote:
Originally Posted by Uberanwar
Посмотреть сообщение
Hey everyone!
I was wondering if I make some includes, such as cmds.inc which contains the commands of the script, stocks would have its include too. Is that a good practice?
I believe it is. I do this all the time to keep track of everything. I haven't run into any trouble because of that yet.

I hate when you enter a gamemode and /everything/ is in the same file.

My includes:
pawn Код:
#include <a_samp>
#include <a_mysql>
#include <timec>
#include <streamer>
#include <strreplace>
#include <foreach>
#include <proxdetector>
#include <whirlpool>
#include <mysqlsettings>
#include <sscanf2>
#include <zcmd>
#include <colors>
#include <playerinfo>
#include <factioninfo>
#include <buildinginfo>
#include <vehicleinfo>
#include <weaponinfo>
#include <stocks>
#include <dialogs>
#include <loginquery>
#include <admincommands>
#include <playercommands>
#include <factioncommands>
#include <buildingcommands>
#include <mapping>
#include <crashdetect>
#include <anticheat>
#include <hitbox>
#include <actors>
Reply
#3

Modular programming: https://sampforum.blast.hk/showthread.php?tid=597338
I have not seen a modular gamemode yet where the modules are put in .inc files or even in the include folder. I have no idea whether doing so is a bad practice (I doubt it is).

My layout:
Код:
\project_folder\gamemodes\
	gamemode.pwn
	gamemode.amx
	\project_folder\gamemodes\modules\
		\project_folder\gamemodes\modules\player\
			core.pwn
			connect.pwn
			disconnect.pwn
			spawn.pwn
And I include them like this:
PHP код:
#include "modules\player\core.pwn"
#include "modules\player\connect.pwn"
#include "modules\player\disconnect.pwn"
#include "modules\player\spawn.pwn" 
It's easy for me to distinguish libraries from gamemode modules doing it like this and I believe that's the only reason why it is done like this.

I could also put my modules in the include folder and include them like so:
PHP код:
#include <modules\player\core.pwn>
#include <modules\player\connect.pwn>
#include <modules\player\disconnect.pwn>
#include <modules\player\spawn.pwn> 
Reply
#4

Code should be grouped by purpose, not by type. The idea behind splitting it up is to not have to look at code you're not currently working on.

Also I do not work out of the pawno/include folder. I leave that folder as it is so it can be overwritten as a whole during updates. I create a "source" folder in the root of the server directory and work from there. So a typical include line can look like:
PHP код:
#include "..\source\3rd_party\plugins\sscanf.inc" 
or
PHP код:
#include "..\source\minigames\stadium.inc" 
Reply
#5

Код:
#include <scrp/inc/a_mysql>
#include <scrp/inc/CarPrice>
#include <scrp/inc/CameraMover>
#include <scrp/inc/easyDialog>
#include <scrp/inc/fixchars>
#include <scrp/inc/GetVehicleSpeed>
#include <scrp/inc/izcmd>
#include <scrp/inc/progressbar>
#include <scrp/inc/sscanf2>
#include <scrp/inc/streamer>

#include <scrp/server/define.pwn>
#include <scrp/server/enums.pwn>
#include <scrp/server/forwards.pwn>
#include <scrp/server/pragma.pwn>
#include <scrp/server/objects.pwn>
#include <scrp/server/stock.pwn>
4ever
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)