Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
Hei.
I've recently started development of a new gamemode/server and while originally the layout was okay, as it's building up more and more code it seems to be working less.
I have this issue where when I want to script something new, for example let's say I want to script some random weapon pickups - I need three things. The array of data, the creation and the OnPlayerPickUpPickup. First thing I do is the array - but I start to go 'WHERE DO I PUT THE ARRAY DO I PUT IT ABOVE ALL THE OTHERS OR AT THE BOTTOM OR A NEW SECTION FOR WEAPON PICKUPS OR WHAT' and yeah.
This is the current roughly layout of my gamemode (FROM MEMORY):
Includes
Defines
Enums/Arrays
Variables
Callbacks
Custom Functions
mySQL query callbacks
Timers
and I guess that's okay, but I seem to be losing track of where everything is.
Also I split my callbacks up in to sections, so like in OnGameModeInit I would do something like
Initial setup (DisableEnterExits and that sort of thing)
mySQL connection
Objects
Pickups
etc.
So yeah, let's discuss layout options. What do you do? What could I do to improve?
I know some people put different systems in different files and #include them, but I think that'd be a bit of a ballache. Instead of saying 'oh I need to add a new weapon to my weapon pickups, I'll just Ctrl+F and find the array and add it in' you'd have to find out what file it's in, find that file in your /include folder then Ctrl+F through that.
I dunno, it would make it more organized I guess. I'm also developing this server with another person (blewert \o/) and we need a way to contribute to the script at the same time. I guess having systems in separate files then including them would make our lives easier.
Posts: 2,262
Threads: 260
Joined: Mar 2009
Reputation:
0
For me, tis:
Includes
Defines
Arrays / Enums
Variables
Then after that anything really, if I had a group chat system I place the stocks near the commands where it's required etc.
Also pop on the IRC and query me please.
Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
The general reason I and others put arrays and enums etc. above callbacks is because (obviously) the callbacks can't use them if they're declared after them. Most of them get used in OnGameModeInit so it wouldn't make sense to have them at the bottom of the script.
For example my weapon pickup array - it needs to be above OnGameModeInit because they get created there.
I do agree splitting up systems is important - I'm just not totally sure how to do it. I'm sort of put off by the fact of having a million files when I could just have one.
Also, say you scripted something 2 years ago and it's in some file in some directory in some other directory - if the compiler gives an error it's going to say the error is in your GM, not which file. How are you meant to remember what file the script is in?
I should also point out I'm co-developing this with another person - which makes it even harder to organize stuff.
I am definately going to split many systems and include them, for example the housing system, ammunation, bank robberies and stuff like that.
Posts: 1,223
Threads: 5
Joined: Sep 2011
Reputation:
0
Meh, it doesn't really matter what anyone's opinion on this is aside from your own. Though I'm still going to throw mine out there :P
I organize like ****** said no one does. The reason for this...I find it much easier. If I forget the name of the function I just made...variable or anything else - I won't have to search everywhere for it (with "splitting code up in to separate chunks of related functionality" you can lose things very easily. even if they're related).
I do go like most of you...sort of
Includes
Macros
Enums
Arrays
Vars
Main
ongamemodeinit
onplayerconnect
..
onplayerdisconnect
ongamemodeexit
Commands
Custom functions (not publics (those are in a separate place))
Custom functions (publics (not just timers, things for cross server stuff go here too))
Save File stuff (I always put it at the bottom (aside from forwards), just for easier access)
Forwards
I also comment above the beginning of them - keywords. Though I'm not an open source kind of guy.
Posts: 3,488
Threads: 16
Joined: Jun 2007
Reputation:
0
The layout I'm trying to keep in my scripts:
Includes
Defines
Macros
Variables/Enums
Stock functions
Regular functions
Public functions
Callbacks
Reason: before you can use a variable/function, you need to define it. I find it logical that definitions come before parts that use them. Callbacks use functions, functions use variables and variable definitions require defines (#define).
And it makes searching for definitions easier: go to top of the script (Ctrl + Home), use search (Ctrl + F) and the first result is the definition.
Posts: 966
Threads: 5
Joined: Jul 2011
Reputation:
0
What a nice topic to discuss on!
Calling my server a large project would be an exaggeration, but I do follow the same fashion of having separate files. To be more precise, 15 of them. I started doing this in 2010 and I also converted an old mode of mine to use several files.
To whoever this might look difficult to handle... stop using Notepad to script! (or Pawno, quite the equivalent). Use Notepad++ instead, it offers a very convenient way of handling files. And I believe that at least a few of the many plugins assist programmers in creating directory structures even more. Following Slice's tutorial, Notepad++ can also instruct the compiler to compile your code.
The benefits from doing this are immense. A good naming convention for your gamemode files will instantly make you aware of what is where and even with quite a lot of files containing PAWN code, I can still remember the location of certain functions quite well, or at least I have an idea of whether they're positioned in the lower/upper part of the SFSE_*.pwn file. Libraries and methods introduced by Zeex (zcmd) and whoever thought of handling dialogs in a similar way have made things even more convenient, as commands, MySQL result callbacks and much more can be shared between files, so the gamemode is categorized nicely. Writing new code for your mode is easy as well, as the more code unrelated code is in your currently operated file, the more distracted you will most likely get.
And for the record, there's not a problem with getting the location of an error unlike someone pointed out.
So multiple files... good idea!
Posts: 1,464
Threads: 11
Joined: Jan 2008
Reputation:
0
I must disagree with you guys about spreading the gamemode into separate files.
I am using 20 includes + couple of filterscripts, so splitting up the code even more would make the gamemode look like it was blown up. I don't have any opinion regarding color defines and shit like that placed in their own files, because I don't really have too many of them laying around.
I like the idea of having "visual code" (aka the gamemode) in 1 single file and the systems which 'run' the gamemode and offer handy functions in their own include files. Also I'm grouping up the code so the related functions, timers, commands and such are in the same section of the gamemode making it very easy to edit the system which is under development or being fixed.
Posts: 3,793
Threads: 196
Joined: Jan 2010
Reputation:
0
I just add my core gamemode functions inside its own include.
includes
defines
enums
variables
forwards
main(){}
publics
commands (replaced OnPlayerCommandText with OnPlayerCommandPerformed, so...)
other publics
functions
sql dump at the bottom
Posts: 15,941
Threads: 0
Joined: Jun 2008
Quote:
Originally Posted by VincentDunn
It gets glitchy when you have multiple files open I guess
I was working in an include using notepad++ and had a couple of errors when I compiled. I fixed them and hit ctrl+s to save. Then when I went to Pawno to compile, and it wouldn't recognize that I've updated the include.
|
That has never happened to me ever, in MANY years of coding!
Posts: 154
Threads: 13
Joined: Dec 2010
Reputation:
0
Includes
Defines
Variables
Enums
Callbacks
Public timers
Custom Callbacks
ZCMD Commands
Mysql functions
Stock functions
but it gets EXTREAMLY messy sometimes, too much clutter, so I think i'll just add all my important defines and stocks, central stuff (such as small but important player variables), into one include to make it much easier to read and edit stuff.
Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
Well I've decided to do a bit of both. I'm still going to have a lot of stuff in the gamemode but some 'systems' will be in files such as the ammunation script. I don't like the idea of having a million files. To me it's like taking 5 shopping lists in to a supermarket - each one has a different 'category' of food or something. It's simpler to just have 1.
Posts: 58
Threads: 0
Joined: Mar 2012
Reputation:
0
Look up PAWN-Boilerplate project by Slice for solid script layout.