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

Get help using Construct 2

Post » Tue Sep 11, 2012 1:32 am

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
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Sep 11, 2012 11:07 am

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.
B
14
S
2
G
6
Posts: 52
Reputation: 3,633

Post » Tue Sep 11, 2012 11:27 am

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...
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Tue Sep 11, 2012 11:34 am

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.lanceal2012-09-11 11:37:30
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Sep 11, 2012 12:16 pm

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).
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Tue Sep 11, 2012 5:08 pm

@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.
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Sep 11, 2012 5:11 pm

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.
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Sep 11, 2012 5:51 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Tue Sep 11, 2012 6:39 pm

ok, thanks :)
B
68
S
21
G
15
Posts: 701
Reputation: 15,604


Return to How do I....?

Who is online

Users browsing this forum: Kagubro, Solomon and 23 guests