[SOLVED] Create a server-based game with Defold: where to start? Any advices/recommendations?

Hi all!

Today I need you advice for my next/real project.

A bit of context
I’ve been (slowly) building up my skills with Defold for a while now, through a single project that serves as a ‘use case’ for pretty much all the features I’d like to test the implementation of. It was not supposed to be an actual game, but feature after feature…

I’ve made tons of mistakes in the process, lost a lot of time on fun but pointless things, created a million tools/configurations that I ended up using 10% of the possibilities, but at least today I know what I can handle properly (on Defold side), what takes time, generates bugs, or requires recurring tasks/rework.

I’m giving myself another 1-2 months to wrap up what needs to be done (to create a sort of “polished prototype” that I can show to my great-great-grandchildren). After that, I’d like to move on to a ‘real game,’ which I’ll describe briefly below.

Of course, I’ll share an HTML5 demo (and maybe a post-mortem) on the forum at this moment.

Quick overview of what it currently looks like.


Next project (the real deal) = MMO (yes, that’s ambitious :face_with_raised_eyebrow:)

Anyway, now I’d like to learn the server side, in order to create a multiplayer game that I can play with friends who will be my beta testers right from the start. I’ll start small but will keep adding things over time.

Let’s imagine that I want to create a space MMO that fits the super macro description below. A mix between some browser space MMOs I’ve been playing in the past and Advanced Wars-like graphics/UX/gameplay.

1/ Initially: no ‘direct’ player interactions:

  • Each player can colonize planets, build and produce on them, and then move around in space. They can also engage with AI entities (grinding).
  • All player resources / construction / production / movement / combat info are stored online.
  • If possible, basic interactions like resource trades etc.

2/ Eventually: asynchronous enemy encounters (no real-time)

  • Two fleets of players crossing paths could interact, whether the players are online or not.
  • Battles are resolved automatically, and optionnally, there are a visual representation for present players, but without any possible interaction—just as spectators.

3/ In the distant future: real-time combat

  • Similar to the previous point, but with possible interactions during battles. However, I imagine that’s a different topic.

Creating an MMO with Defold: Any advice/recommendations?

I used MySQL centuries ago to create PHP websites, so I have a basic understanding, albeit rusty. But in the context of a server-based game made with Defold, I’m starting from scratch. I just want to create something clean, scalable, and easy to maintain, using standard stuff.

So, I’m wondering about this server part: where should I start? What are the basic/core concepts? How should I logically proceed to learn and test step by step? What type of server should I consider (even if this is probably not the most important at this point)? etc.

Does anyone have good ‘guides’ / post-mortems/websites or any helpful resources?

Ultimately, maybe the server part isn’t specific to Defold at all and could be done independently, and then connected to Defold so that people would be able to play.


In short, if any of you have experience/advice to share, please feel free to do so. :pray:

2 Likes

I only have time to answer one of your questions at the moment…

Here is a brief list of multiplayer backends that have been used by various members of the Defold community in the past:

Lua:

JavaScript / TypeScript:

JavaScript:

Not a multiplayer backend, but moreso for general networking in Lua:

Between these solutions for your use-case, I recommend Nakama. If not, then my next pick would be Colyseus.

6 Likes

I totally agree with the above recommendations. To this I would also like to add the WebSocket extension if ity turns out that you’ll go for a Node.js backend or similar:

2 Likes

Hey, thank you both for your answers!

I’ve heard of Nakama in the past, it looks cool; For some reason, I thought I would need to pay, but it seems that payment is only required if the game is hosted on Heroic Labs’ servers. I really hope I’ll be able to consider this option later, but I don’t need it in the short term.

Plus, it was really important for me to confirm that it could be a viable solution for my next project.


As someone new to server-related stuff, I have 2 (+1) questions that may appear silly, but… :

1/ When you mention Lua, are you referring to the server-side game logic itself? (For example: battle resolutions). Would be really awesome to be able to write server-side code in Lua :thinking:

2/ Talking about the backend… In my 1st project, I export millions of Google spreadsheets in .csv format and inject them into tables in the game… Everything is local, within the client build. However, if I want the parameters to be on the server side (so I can easily distribute the game parameter updates), this method will no longer be viable. So, I was wondering how to proceed.

By ‘backend,’ do you mean a website/interface where I can edit the database or the game parameters? (that kind of stuff)

3/ Are there any examples of games/playable prototypes made with Defold that also use Nakama?

Yes.

Client / Server example:

Thread with some resources:
https://forum.defold.com/t/how-many-defold-users-are-utilizing-nakama/

I recall totebo working on a Nakama game, however I’m not going to volunteer or ping him about it.

Backend in this context means a server that the clients (players) do not have direct access to that is running game logic, editing a database, communicating with other online services, authenticating users, etc. All of this should be protected from the mishandling of clients, so we run all of it on the backend. Only developers should have access to it.

As stated above, this is the opposite of what you want with a multiplayer game.

Anyway, there are a million technical details I could cover about how to properly implement something like an MMO. I recommend you seek out articles online.

You should do as much research on multiplayer as you can before starting. You need to know about things like P2P, server authority, client-side prediction, how data is sent over networks, the programming paradigm for dummy clients sending messages to a server then rendering the server’s response, server-side security, how to deploy and maintain a server on some cloud provider like Google Cloud Platform or Amazon Web Services, how to encapsulate and manage your server-side application in a Docker container, etc.

Also keep in mind that realtime multiplayer games generally need to be created from scratch. Almost your entire codebase will revolve around the client-server paradigm, and it will look nothing like a singleplayer codebase. Typically singleplayer games that also have a multiplayer option are actually only multiplayer: starting a singleplayer session launches the game on a local server so the multiplayer game architecture can be reused. Otherwise, you may have to rewrite all of your game’s logic on the client.

This is certainly not an impossible task, but it is an arduous one. Luckily backend frameworks like Nakama will assist you greatly. Good luck!

4 Likes

Thank you for all this information! Quite a few keywords that will help me understand which direction to head in.

I know that I’ll have to learn a lot of things; for now, it’s like magic to me (similar to how Defold was at the beginning). That’s why I’m planning to significantly narrow down the scope of the client side, with a simpler game, a more ‘pure’ user experience, and fewer assets to create.

Space+2D Ships+GUI is easier and less demanding than animated characters casting spells in heroic fantasy environments, tons of customization options etc.

In short, thanks again for your feedback. I’ll go through them carefully when I dive into this (and I think it will be helpful to others as well).

1 Like