nutmix's Forum Posts

  • Hi nutmix,

    tl;dr: use NodeJS - never ever even think about some other way (incl. services like Photon, etc.; Java, PHP, neighbors cat or whatever comes into mind) to realize a real-time-multiplayer backend! Just don't (speaking of the "state-of-the-art" in 2017)! If you ignore my suggest and do, you'll regret it some day as bad as possible.

    Brilliant, thanks for the detailed and informative reply!

    I have actually gone down the node.js route for the game engine prototype and its working nicely. For the backoffice probably ill use a separate grails based system + mysql as you can develop an enitre backoffice in half a day, and mysql is a better option for finanical transactions due to its referential integrety.

    Node is good, and with the ECMAscript 6 editions (classes, let, template literales etc) js is almost bearable!

    The only issue I have found, without a solution yet, is now to have a clustered multiplayer object on a single server. I.e. if you use the node cluster feature, it creates multuple node child processes using fork. If I have a player connected with a socket in one child process, he cant access the mulitplayer game instance running on another child process.

    I have seen some solutions to this, e.g.

    1. Using another layer of sockets (ugh)

    2. communicating throught he parent process ( See this post: https://60devs.com/performance-of-inter-process-communications-in-nodejs.htmlfor performance measurement of child.send())

    3. Using redis. I am not sure about this one - it implies that one process can read/write to another process's socket, which I dont think is possible....

    4. clever load balancing which sends traffic intelligently to a spefic process in a cluster, so that all players get funneled intot he same process untill a threshold is reached, then uses the next etc. I havent resarched if it is possible (e.g. each clustered process be on a different port or similar). I saw there is actually a node based load balancer when you can implmenet clever logic.

    I have decided to ignore this for now, and only have a single node process. If/when this goes into production, I can alwosy switch to smarFox which has clustered multiplayer built in (and java has inter-thread comunication). The problem with smartfox is I would have to write a plugin for it for C2, as it has quite an extensive client library and complex protocol. I tried writing plugins for C2 once - it was not easy.

    However, Ill checkout colyseus first - nice one!

  • The answer to JSON parsing part is rex_hash: rex rainbow comes to the rescue again. It even handles json arrays, although the resultant code for complex json is not pretty.

  • The data I get back from a game server is Json. e.g. If I send the login message, the responses are things like:

    {"message":"loggedIn", "data":{"username":"bob", "balance":100.0, "session":"asdfasd"}}

    {"message":"error","data":{"message":"something went wrong"}}

    {"message":"tick","data":"{very complex data...

    In the websocket->On message I need to be able to do things like

    if ($response.message == "loggedIn") then set txt=$response.data.username else if ($response.message == "something_else") then call some function...

    and

    for each ($respose.data.item) -> do something with ($respose.data.item.name)

    Assuming there is a way to parse the websocket.MessageText, how would one do:

    on some event: do A

    if X do Y else do Z

    do B

    I have never figured this out in C2. I am guessing also that each layout can only have one event sheet with one WebSocket On Message in, it as, you cant read from a socket twice and get the same message.

    Surely abitrary json parsing should be native to C2? Or are there so few games accessing game servers or content from other sources?

  • Update- by luck I found the SDK manual, completely hidden! Its actually on this page: https://www.scirra.com/manual/15/sdk but what I didnt notice was there on the left, you can click on the word "SDK Documentaion" and there is the info in the dropdown. They should have put a link to it in the sdk page, like "start here" or "goto manual"

  • I found the SDK page: https://www.scirra.com/manual/15/sdk, which has a template but no information on how to write plugins.

    I could not find any tutorials, nor info in the main manual.

    E.g.

    1. how does the plugin include external js libraries for runtime only (I only see common.js as the way to include libraries)

    2. how to pass multiple parameters in/out?

    3. what is the difference between a c2addon and a plugin?

    4. How the plugin and C2 runtime and C2 editor interact.

    The particular plugin is runtime only, no layout stuff.

    Any suggestions as to resources or tutorials? Perhaps some hello world and slightly more complex examples?

  • The multiplayer plugin is great, but is peer to peer, and I need central server code for my games. The servers will be writing to a database, doing AI logic and bots, calling other systems, having complex game logic and certified RNG etc. In my case I am not doing any server side physics or player movement - more a real time turn based game.

    There are many options, I was wondering if poeple could share what they have used succesfully in conjunction with C2, and if they had to write costom connectors on the client side, or could get away with the stock websocket plugin? Not having to write any C2 custom js plugin code for a propriatary client connector would be a big advantage.

    Here is my guess at pros/cons of some technologoes, assuming:

    1. runs on linux AND windows (linux for the production sever, windows for testing on your pc)

    2. easy to learn.

    3. plenty of documentation

    4. database support

    5. backoffice application (UI) support.

    6. Ideally free or free up to a certain number of concurrent users.

    Dedicated game servers:

    1. Smart fox Server

    a) purpose built for games

    b) very popular (for flash games at least)

    c) can use websockets.

    d) uses java

    e) free version and paid versions is not expensive.

    f) basic database access, but ORM of choise can be added in theory (such as hibernate)

    g) The Client api (Which is much higher level than websockets) must be integrated with C2 (unfortuatenly) which is a big job.

    h) all their examples are flash based, nothing for the websocket api.

    2. electro-server

    a) now defunct

    3. Photon Engine https://www.photonengine.com/en-US/Photon

    a) windows only, not suitable for linux servers.

    4. Union server http://www.unionplatform.com

    a) seems to be dead by the forum activity

    b) cant work out what OS it runs on

    c) seems to be java/javascript

    Generic servers which you can write your server logic and run on any OS:

    1. grails 2.5 + tomcat

    a) can write backoffice UIs in very little code.

    b) GORM/Hibernate does all the DB work for you.

    c) websocket plugin is tricky to use.

    d) version 3.1 is not there yet.

    2. node.js

    a) free & lots of plugins.

    b) uses javascript, which, for me, as a java/C++ dev, is an abomination.

    c) very basic DB support?

    d) no backoffice UI support.

    e) researching this, it seems node is single threaded. Thus critical game timers would wait on the same event queue as incomming messages. Nodes "solution" to this is to cluster addtional forked worker processes. Inter-process communication between these forked processes goes through the parent "master" in the form of messages, which is not scalable. The general solution is to have another layer of servers with the game logic, and use RPC or sockets to connect the "front end" node processes with backend game logic servers. Checkout pomelo for an example of this https://github.com/NetEase/pomelo/wiki/Pomelo-framework-overview

    3. Netty.

    a) java nio server.

    b) easy and free.

    c) game server source available https://github.com/menacher/java-game-server.

    Any others?

  • I have a function which places a sprite, then it checks if its overlapping, and ifso, calls it again. This recursion should keep moving it until it is not overlapping. But unfortuatnely, it does not work.

    I just tried something wierd and it worked, but dont know why.

    Above I have moved the overlap detection code out of the function. So in theory, this code should never be called, or at least called only when the event sheet which contains it is included into the main event sheet?

    Any ideas?

  • Wow, that was easy, Rojo, you are the man!

  • you can do stuff like "set position object (image point Y)". I .e. chose the image point.

    But in expressions, you dont seem to be able to. e.g. you can say

    Value -> 100 + object.imagePointX

    but you cant say which image point it will get the X value from. I assume it is always using image point 0?

    Is there any way to get the x and y of image point 1?

    The reason is I want one image point in the center to allow easy centering, and I want another one which is more or less the top left to make object placement easier. I know I can calculate one from the other by adding/subtracting half the width, but I would prefer to be able to use the image points directly if possible?

  • I think I have sussed it after reading https://www.scirra.com/tutorials/556/understanding-picking-with-respect-to-families

    However, the resultant code is too long to hand type here.

    Basically, I have a function "placeShip" with "pick instance with UID Function.Param(0)" after it. Then I call this from the "for each ships" function. Then I have a separate event "ships Is overlapping ships" with a "Pick ships instance 0" after it. I am hoping that this is picking the first overlapping instance from the family, not the first instance in the family (which may not be overlapping).

    How do people paste code or screenshots into the forums?

  • I want to place some objects randomly, but make sure they dont overlap. I am using families because I also want to set some instance variables at the same time. Say the family of sprites is called "ships"

    I can do something like this:

    on start of layout 
    for each ships                 -> ships -> set X to ...     
                                   -> set myinstanceVar to ...[/code:2px6zc52]
    
    Now I want to do something like "if ships is overlapping ships then start again for this ship" WITHIN the for each ships, but cant figure out how to do this.
    
    I thought of using some nested functions, but you dont seem to be able to pass objects to functions (unless you pass the UID as an integer), which makes it harder.
    
    I saw some function examples with "remember picked object" set somewhere, but could not find this feature.  Anyone got a hand example?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am assuming that the drawing coordinates are relative to the canvas container thing, not the top left of the projects layout, as I center the layout (by "set scroll X/Y" to the center). I think its your plugin rojohound.

  • I used to be a guru in C2, but havent used it for 2 years, coming back I cant figure out for the life of me how to draw a line.

    I have the canvas object added to the project. I dont know if this canvas object is part of C2, or some plugin I installed years ago.

    Anyway, when I do Canvas-> Draw line from (20,20) to (200,200) with color "black" and line width 1.0

    Nothing happens no lines are drawn.

    How do you define which layer the canvas is drawn on?

    Any ideas? Probably something really simple.

  • Hi, A friend with a mac is asking if he buys a C2 personal license now, if he can upgrade for free to C3 when it comes?

    This is assuming that C3 supports Mac natively

    Simon.

  • Sadly, these do not seem to be suitable for a scratch card because

    a) you get staccato dots, instead of the required smooth swiping reveal, if you do it quickly. I tried changing the project to use Is Touching instead of every tick - same problem. I guess this is a limitation of how often C2 samples the mouse.

    b) its not possible to know how much of the canvas was scratched, to complete the reveal and award the prize.

    c) it doesnt work on mobile (ipad at least), even if you use touch events. No idea why.