SA-MP Forums Archive
Organizing The Script - Optimal Solution? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Organizing The Script - Optimal Solution? (/showthread.php?tid=541883)



Organizing The Script - Optimal Solution? - RedFusion - 15.10.2014

Hi.

I have a problem when it comes to writing big scripts. It always gets to that point when the code becomes too big to easily overlook and edit. I've tried to organize my scripts into smaller sections, but it's hard to decide what i should put in it's own section and what not to. Often if i make too many small sections i run into compiling problems.

Here's an example:

Either i put all the database reading/writing code in its own file (which can be alot of code to overlook), and clothing script in another. Or maybe i should put the database reading / writing relevant to the clothing script in its own file, which means i have to read the database atleast twice, right?

The reason i make this thread is because i want a solution that works nice, and looks nice. Are you people satisfied with how you solve this problem, then please tell me how you solve it.


Re: Organizing The Script - Optimal Solution? - Dignity - 15.10.2014

There really is no "solution" as it all comes down to personal preference. You should consider using modules though.

I personally use modules in my scripts and put all relevant functions together (including SA-MP callbacks relevant to a specific script) and then list them under a category by using comments. I also put my SQL queries into modules relevant to what system they are used for.

You should take a look at SouthclawJK's Scavenge & Survive. It's probably one of the best examples you can get and it might give you some ideas.


Re: Organizing The Script - Optimal Solution? - Pottus - 15.10.2014

Modular approach is key and as Mionee mentioned look at S&S it's the way a script should be written YSI is another good example.

I will give you an example with your clothing script.

So what you want to do is break it down your going to have the following.

data (Information about usable objects, playerdata, enums)
core functions
commands
textdraws
database

That should will be enough to make the module easy to manage a quick tip when it comes to using y_hooks is include all these sequentially in your gamemode for example.

pawn Код:
#include "gamemode\clothing\clothingdata.pwn"
#include "gamemode\clothing\clothingcore.pwn"
#include "gamemode\clothing\clothingcommands.pwn"
#include "gamemode\clothing\clothingtextdraws.pwn"
#include "gamemode\clothing\clothingdatabase.pwn"
Order matters when doing this by putting the data first your variables will be recognized by all other includes. Now the only real issue with breaking it down so much is you lose some ability to encapsulate your code with the static modifier. If you want to increase your encapsulation you would need combine includes so this is something to keep in mind when deciding how you want your system to be modularized. With a clothing system there is going to be a lot code so it is a good idea to use several includes.