Best way to organize your scripts.
#1

I wanted to start a simple discussion about the best way to organize your SA-MP scripts.

Personally, ive run into issues where the script gets above 10k+ lines and its just such a hassle to keep organized and find things when you need to edit code.

Ive seen some people split certain systems into in inc files and others into filterscripts. Personally, i cant due this because im not quite sure how to share the variables between separate script files.

I wanted to know, how do you guys organize your scripts?
Reply
#2

The easiest way is probably to group your code into sections, e.g. Housing, Businesses. And then put a comment above the section saying what it is. Then when you need to work on it just CTRL+F and search for it. That's probably the most simple method but it can help.
Reply
#3

If you have issues with having over 10k lines, you should probably try to make a modular gamemode.

I keep my scripts in a general order (includes first, defines, enums, arrays, variables, public functions, commands, custom public functions, stocks) and comment new sections out so I can easily CTRL + F to them. Also, memorizing your code helps tremendously when you need to edit existing code.

That being said, I usually write new code in filterscripts since I tend to get lost in a bigger gamemode.
Reply
#4

Quote:
Originally Posted by NewerthRoleplay
Посмотреть сообщение
The easiest way is probably to group your code into sections, e.g. Housing, Businesses. And then put a comment above the section saying what it is. Then when you need to work on it just CTRL+F and search for it. That's probably the most simple method but it can help.
Ive done that for a while. Works, but can still get cluttered in my mind. Plus i know, with me atleast, alot of my systems intertwine. Player vehicles depends on Houses, which then relys on the mission system. Then the mission system twines into the vehicle system and player vehicle system... bleh bleh bleh lol.

Quote:
Originally Posted by Mionee
Посмотреть сообщение
If you have issues with having over 10k lines, you should probably try to make a modular gamemode.

I keep my scripts in a general order (includes first, defines, enums, arrays, variables, public functions, commands, custom public functions, stocks) and comment new sections out so I can easily CTRL + F to them. Also, memorizing your code helps tremendously when you need to edit existing code.

That being said, I usually write new code in filterscripts since I tend to get lost in a bigger gamemode.
May i ask, how do you do that and link the variables between the main script and the filterscript? If i could figure that out, i would just tie off my systems into filterscripts and leave the main bit in the gamemode.
Reply
#5

https://sampwiki.blast.hk/wiki/Per-player_variable_system
Reply
#6

I feel like a proper idiot now. Haha.
Reply
#7

Not recommended.

https://sampforum.blast.hk/showthread.php?tid=268499

@Rokzlive: Use CallRemoteFunction and a tutorial about how you can actually do that can be found here: https://sampforum.blast.hk/showthread.php?tid=516617
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
Split it in to includes, not in to filterscripts.

Anyway, most of the time variables shouldn't be shared between different parts of your script. Your vehicles system has variables, your business system has variables - there is no need for the vehicles system to have access to the variables from the business system, and vice-versa.

This is called separation of concerns, and has been discussed at length in almost all programming circles, including this one in the "Discussion" subforum. It makes me physically cringe when people just have one huge "PlayerInfo" variable (not just because it is a terrible name) that is global and contains literally everything. You should have one variable for a player's vehicle's data, one for their businesses, one for their messages etc; with each one isolated from the others.
I completely 100% agree. In the end, i think the way i coded my script plays alot into not being able to subdivide it. Add that and the fact that ive been fairly dorment as far as coding is concerned, ive kinda forgot whats where in my script. Ultimately ill just recode it to use inc's for all the seperate systems.
Reply
#9

But it is possible make a mod on the includes. Such as registering on first, commands for players in others etc. ... And tie it all together with the help static variables. If some functions are located in filterscripts use PVar's
Reply
#10

Quote:
Originally Posted by Whiteman
Посмотреть сообщение
But it is possible make a mod on the includes. Such as registering on first, commands for players in others etc. ... And tie it all together with the help static variables. If some functions are located in filterscripts use PVar's
That's essentially what im doing now. Makes it much more organized.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)