Generating content on the server?

0 favourites
  • 8 posts
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • This is not so much a 'how do I?' question as a 'is it possible'? I have had an idea for a game kicking around for a while and started work on a version of it in Java a couple of years ago before shelving it when life got in the way. I've been looking to start work on it again and was considering moving to HTML5/Java script in order to be able to run on smartphones and tablets as well as in browsers. Then I came across construct 2 and I've been able to make a lot of progress in a few days.

    However, there is a major issue that I'm not sure Construct 2 can handle. The game is intended to be a tactical simulation/manager game where the player sets up tactics, upgrades units etc between battles then hits 'GO' and then watches the battle unfold. The player should also be able to analyse replays of battles carefully (fast forward, rewind, pause, step forward etc). For a 1 player game against AI I can see how this could be done in C2. The battle is controlled using sprites with different behaviours and events, but every tick the positions and states of every sprite could be saved to a web storage DB (or whatever type of storage C2 provides that would be appropriate), allowing replays of the exact same events.

    For multiplayer though, battles would take place at regular time intervals (i.e. once a day at 3UT say). In my original Java version, this would have worked fine as you could simply run the battle from a scheduled task on the server using the submitted info of the players, save the results and then players would all be viewing the same replay in their browsers when they log on. From what I have read so far in tutorials and the manual I can't see how C2 could be used to do something like this. Please let me know if this is possible somehow. I just need keywords of any features to look into further, not a full explanation of the whole procedure. I just want to know if C2 is the right tool for this task.

    I really hope this is possible as for the battles themselves C2 provides the perfect range of behaviours and events to be able to implement what I want. I'd love to be able to spend 100% of my time on the game design and content rather than 90% of my time debugging crappy event detection code...

  • Well, C2 can communicate with servers via AJAX, so you'd use this to get each player to submit their move to the server (as a XML/JSON string, for example). Then, in the application, poll the server on startup, or every x seconds/minutes/days to see if the opponent made their move yet, download their actions and play them on the device.

    For asynchronous games like this, C2 should be able to do everything in a pretty similar way as you were doing in Java.

  • Thanks for that. The only thing that bothers me with that approach is ensuring everyone has exactly the same reality. These battle sequences will be complex and contain randomness in some of the events. I can ensure seeds are consistent (if C2 can do that? I assume so??) to make sure the dice roll the same for everyone, but I'm not sure whether I'd trust every browsers and device to detect every collision at exactly the same tick, ensuring all subsequent actions are completely consistent etc etc. It feels safer to crank the handle in a server process, save the outcome and have everyone look at that, rather than everyone crank their own handles with the same initial conditions hoping that the result will be identical.

    Am I explaining this clearly enough? I could make it so that whichever player first logs in to view the results the details gets saved then everyone else would just be viewing a replay (although the experience is the same and the players are none the wiser) but this falls down as soon as two player log in at the same time, which would happen at some point.

  • If your logic is deterministic (i.e. a given set of inputs always results in the same output) then it shouldn't matter whether it's played out on the device or on the server.

    But if you're using any element of randomness, or relying on any property that might change between devices (consider, for example, sprites being intialised relative to the client screen height/width - they may then collide on some devices and not on others) and you want to ensure that every player experiences a consistent reality, then I'd suggest you resolve the game logic on the server and then each player downloads and simply "animates" the result.

  • Agreed with tanoshimi.

    By the sound of it, your server should produce the replay, and the players will have a C2 replay viewer (that allow them as well some "programming" of the battles through the interface you'll have determined).

    The server will serve the replay either in Json (for arrays or dictionary) or even in XML.

    This way you ensure both clients will replay the very same sequence, having had the randomness calculated on the server side to ensure the same result for both players.

    Server side isn't managed with construct2, it needs to be handled in regular coding language (java is a possibility, javascript is another on a node.js server for example).

    The fact is the clients should merely be replay viewers with an interface to allow each player to determine their next moves (sends the infos to the server).

  • Bogdanovist

    Your issues are standard MMO issues. Your server-side coding will handle those, and your C2 "game" (quotes because the real gameplay takes place on the server) will simply act to accept player input and display output from the server. C2 is totally capable of implementing an application to carry out those two roles.

    Client-server communication can utilise a third party AJAX plugin or the official WebSocket plugin - or a comms plugin/behavior that you write yourself ;).

    As for the question in your topic heading, C2 is not a tool to handle that. Your choice of tool for that will depend on your server-side technology.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks all. I agree with everything that's been said. It's a shame C2 can't be persuaded to handle the server side of things as the behaviours and events framework has everything I need for implementing the battle side of the game.

    My one last point in desperation is whether there is any browser out there that could be persuaded to launch displaylessly on the server, open the address of the C2 'game' in order to trigger the battle using C2, saving the results each tick for players to later view? The server 'game' would be a different thing to the player game in order for the required battle(s) to be resolved simply by navigating to the page (i.e. the server 'game' would talk to the database which would tell it how to setup the pieces etc given what the players have uploaded).

    I know this is would be a very odd workflow and maybe there is a Java (or something else) toolkit out there that would give me equivalent functionality to the C2 behaviours and events for constructing the server side of the game, I just haven't seen anything that works so nicely as C2 does for doing this kind of stuff.

  • ... My one last point in desperation is whether there is any browser out there that could be persuaded to launch displaylessly on the server, open the address of the C2 'game' in order to trigger the battle using C2, saving the results each tick for players to later view? ...

    Aren't you really asking for a server-side app that opens a web page whose source will be the index.html generated by C2 - that in turn fires up the exported C2 runtime, which will accept player input and display output from the server?

    All browsers will do that, without any special persuasion - that's their job. The work is in building the server-side app. That's something that's really quite different from the runtime that C2 is designed to generate. I don't know of any C2-like toolkit that's designed to do that. Maybe one day someone will build one atop NodeJS ...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)