Page 1 of 1
how should i do this?
Posted: Sun Dec 11, 2011 6:29 pm
by stefans
I'm planning to add a grid to my game, it will be like 15 x 15, (browser game) but the problem is, i want it to be a farm, so it has to save the data from each grid, for each player apart..
How can i do this?
Re: how should i do this?
Posted: Sun Dec 11, 2011 6:43 pm
by Jackolantern
We need a bit more info. What do you mean by "save the data"? What is going to happen in each grid? Will it happen server-side or client-side? Basically explain how it is going to work from a game design standpoint as much as you can, and we will try to steer you in the right direction!
Re: how should i do this?
Posted: Sun Dec 11, 2011 6:57 pm
by stefans
so this is my grid:
Code: Select all
<table>
<?php
$x = 0;
while($x < 15) {
$y = 0;
echo "<tr>";
while($y < 15) {
echo "<td style='border: 1px solid black;'>$x - $y</td>";
$y++;
}
echo "</tr>";
$x++;
}
?>
</table>
it creates a 15 by 15 grid,
how do i save the data of each field?
so let's say you're player one,
it has to be saved for player one, what field (x = 0, y = 0, etc..) and the state of it. I can do it with mysql, but it takes allot of fields.. or allot of rows if i do: playerid, x, y, state.. it will take 225 rows for each player.. so that's allot..
Re: how should i do this?
Posted: Sun Dec 11, 2011 7:38 pm
by Jackolantern
Where are the actions that occur in the grids taking place? Server-side in PHP or client-side in Javascript?
Re: how should i do this?
Posted: Sun Dec 11, 2011 7:47 pm
by stefans
i don't use any javascript, so server-sided php i guess XD,
i didn't make any actions yet..
Re: how should i do this?
Posted: Sun Dec 11, 2011 8:09 pm
by Jackolantern
Is the 15x15 grid a shared environment, or do players each get their own?
Re: how should i do this?
Posted: Sun Dec 11, 2011 8:11 pm
by stefans
each of them get their own,
it's not a map or anything,
it's a farm :p so, it's different for each player
Re: how should i do this?
Posted: Sun Dec 11, 2011 8:38 pm
by Jackolantern
Well, having 225 fields on a database isn't too bad. You could break it up so that each row has its own table, but then you will need to do some join logic.
You could do 225 on one table, but be sure that A. you keep all of the names well-organized in a way that will allow you to easily differentiate them in code. Names like "Third row" are bad because they are not code-friendly. Names like "row6col12" are much better for code because they use numbers which will allow you to "build" the name of them in code. B. You will need to reduce the amount of queries you make to the database. 225 queries per save will bring your server to its knees. However, adding 225 pieces of data to the table in a single query is much more manageable.
I am thinking about other options. It feels like there is something better, but my brain is not working. I don't want to get into saving JSON into the database, because that will involve a lot of parsing that may be too much for you at the moment. Maybe someone else will chime in with another option. If nothing else, saving JSON-formatted data or something similar may be the only good alternative.
Re: how should i do this?
Posted: Mon Dec 12, 2011 10:41 am
by stefans
Thanks anyway :p
i'll just see what i'll do..
Re: how should i do this?
Posted: Mon Dec 12, 2011 12:40 pm
by Jackolantern
What was wrong with what I said? Did it not make sense?