GameMaker GMS2 Networking

A

ancientarts

Guest
Hi, i'm attempting to make my first multi player game. trying to make it 1-4 players and it is a top down survival rpg. I was making it using the native gml networking functions when i cam across videos saying not to. and then found a youtuber that was using python3 and gms2 and his course is on UDEMY. but i read the reviews and said the course was not informative so i was hesitant to buy it.

guess my question is where should i start, any links to tutorials or courses?
 
M

MishMash

Guest
Nothing wrong with the GMS2.0 networking functionality. If you are learning networking for the first time, it doesn't really matter what you use. Ultimately, the networking API itself is less important than your networking infrastructure design, this means how you decide to integrate networking into your game, and how you structure your engine to support easy addition of networking events and such. By default, no API provides this and will need to be specific to your game. At the start, however, it can be overwhelming to deal with too much at once, however as you gain experience, these design patterns will come more naturally.

I hate to admit it, but there are a lot of empty networking tutorials which teach bad habits and don't really have too many considerations for maintainability and ease of expansion/addition of new gameplay components. The best thing to do now is just to stick with GMS's networking and learn the fundamentals first, then you can worry about making it more efficient.

The general argument often boils down to performance, however, YYC makes GMS viable as a server. The difficulty with using a separate programming language for the server is that it requires you to essentially implement your gameplay mechanics twice. While it is common to have a client-side approximation and a server-side genuine calculation, if you use a language outside of GM, you have to do so much extra work on the server to re-implement functionality that GMS gives you for free (e.g. physics, data structure compatibility etc;). Ideally, having parity between your server and client platform is more beneficial than the marginal gains you get from not having to execute additional engine functionality. Especially if you design your game's systems to complement the networking system.

While I cannot suggest a tutorial that does fulfil all the criteria, I will block out the main considerations you should have:

- Establishing a clean disconnection/connection (player management) framework
- Ensuring a certain amount of modularity in your networking system so that the server-state is clear and network control for different areas are managed by separate objects (e.g. you may have one component and set of functions for managing the lobby, another for managing the game state, another for managing entities.)
- Well-defined communication and interaction protocols. It is essential to plan out how different objects are synced, defining who is responsible for managing what and where the server invokes control vs players.

Much of this can come from experience. For example each iteration and each time you work on a game with multiplayer, you will come across all kinds of problems. At this point, like anything in games, it is worth identifying how these problems can be resolved and you can progressively expand on your skill set.

Some common problems that always come up when starting:
- Server integrity -- Ensuring that the server represents a "true" version of the world, and clients are only windows that can offer certain input. Server should verify any action the client makes and invalidate/override that action should it not comply (e.g. accepting location/control input from the client, but verifying it as being a "legal" action). -- Another aspect of this is creating and designing protocols that ensure data is not lost or can be exploited by a client, e.g. the server should have full control over things like inventories, and rather than letting the client directly manipulate this data, the client sends a request, then the server sends an update. (You can think of the client as a series of inputs or buttons, and rather than the client performing the action itself, it sends off a message asking the server to carry out the action, and it then updates once a response is received).

- Disconnection/gameplay state maintenance - It's rather common that people's first games do not handle disconnection and re-connection well. Ideally, your syncing process should be built such that the server can send the entire gameplay state to the client upon rejoin. This can require well-organised update functions that can both update individual objects, but also serve to send mass updates where necessary.

- Buffer/packet size mismatch issues - One thing that can make network debugging really difficult is when you haven't correctly implemented a read routine on either the client end or the server end, causing your reading head to be in the wrong position. At this stage, a valid solution is to create your own packet wrapper which writes the expected size of the packet at the top, so that after finishing reading a packet, you can go back and evaluate whether the number of items read matches the expected size. If it does, then all is good, if not, you an throw an error and reset the reading head to the correct position in the stream.

What i'm getting at is that at this stage, you should ignore using other languages or setups, there are far far far more important things than the underlying API, and using GMS for both the client and the server will provide you with the cleanest implementation, reducing the opportunity for errors and reducing the amount of setup you need, so you can focus on the fundamentals, rather than having to faff around in a language you might not be familiar with. I also personally find that Python tends to be slower than GM for general data manipulation.

Having said that, some tutorials may offer a reasonable starting point, but try and avoid following them like the bible and make sure you do plenty of thinking and planning for yourself, to ensure you truely understand what is going on and are able to design and improve upon the systems that the tutorials outline. Don't become a copypasta programmer :)
 
A

ancientarts

Guest
Thanks for giving such a great piece of information and taking the time to do so. that was amazing. and yea i don't like copy and pasting but just needed info on where to start or start going about programming it. guess ill keep doing what i'm doing in native GMS2 and get it working just to learn from it. thanks once again!
 
Top