What's the best way for this?(ajax)

0 favourites
  • 9 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi everyone,

    I've got a mysql database with 4 million squares using x,y rows. I want to display say 100 by 100 of those square on the screen based on their x,y position. I'm not sure how to go about doing this. I've currently got a php script to download 1 tile at a time but with 10,000 squares I know thats probably not the right way. So I'll work on one that echos back 1 row at a time(100 squares) but the map also contains info per square such as 4 resource types and troop types. So each square is roughly 12 pieces long which makes a really long echo string. Any recommendations using the tokenat to handle those squares without making my construct file weighed down with events? I do have a licensed copy so I'm not concerned with the number of events outside of streamlining the code. Any ideas on transferring that string into variables without bogging down the program?

    Thank you in advance,

    Lance

  • Sounds like something really interesting you're working on. I've done a fair bit of work using Construct with databases and PHP but I've not quite figured the best way to do what you're needing.

    Would it be possible to only have a database entry for squares that contain something? Then use a script to get any entry within the x/y range specified whereby a certain field is not blank?

    This would bring down the number of results returned by the script and be more efficient - but if you need info from EVERY square then it's no good.

    Alternatively, run a script several times, once looking for each resource or troop type? That would also limit the number of results significantly and you could still get every square in the range - again this would also be helped if there are empty squares as it won't be retrieving them.

  • The only efficient way to do this is build a single large JSON string representing all the data for a level then send it all at once, and then loading that in to the Array object. I hope you're not planning to send all 4 million rows at once though! That could be around 20mb of data...

  • lol Ashley,

    No I havent found the perfect world size as of yet. I need to be able to update each square every few seconds. It's a multiplayer game along the lines of civilization. The world is 2000 by 2000 squares but I'm only going to show a fraction of that at a time. Just need to figure out the best way to transfer it to construct.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If it's updated in real time, there are currently no features in C2 that are suitable. AJAX is not designed for real time use. You'll need something like WebSockets, which we have on our todo list, but are holding off supporting until UDP transmission is supported (which makes it even better for real-time use).

  • Ashley

    I have been looking a little bit more into it and was wondering what you think about this potential solution. I've got a grid 9 by 9 in construct that will be the visible map tiles. Live streaming doesn't work and I have no idea how to upload websockets to a godaddy server. How about this. Check visible tiles and send out an ajax call to update them as they become visible? I know it won't be real time but it may work for this in the short term. If I limit movement to left right up down then I'll only be sending out ajax calls 9 times per move.

  • I can do that to generate the physical tiles and just send out another ajax call to see if any player sprites are on the screen every couple of seconds. So at most it would be 10 ajax calls at a time.

  • Never make multiple AJAX calls at the same time. Make a single AJAX call which includes all the required information - it's far more efficient.

    It might work if your game really is not realtime. I would say if you are sending more than one AJAX request every 3-5 seconds, it will probably be unrealiable.

  • ok, thanks :)

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