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?
how should i do this?
how should i do this?
Current project: http://www.mmtycoon.eu
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: how should i do this?
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!
The indelible lord of tl;dr
Re: how should i do this?
so this is my grid:
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..
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>
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..
Current project: http://www.mmtycoon.eu
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: how should i do this?
Where are the actions that occur in the grids taking place? Server-side in PHP or client-side in Javascript?
The indelible lord of tl;dr
Re: how should i do this?
i don't use any javascript, so server-sided php i guess XD,
i didn't make any actions yet..
i didn't make any actions yet..
Current project: http://www.mmtycoon.eu
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: how should i do this?
Is the 15x15 grid a shared environment, or do players each get their own?
The indelible lord of tl;dr
Re: how should i do this?
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
it's not a map or anything,
it's a farm :p so, it's different for each player
Current project: http://www.mmtycoon.eu
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: how should i do this?
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.
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.
The indelible lord of tl;dr
Re: how should i do this?
Thanks anyway :p
i'll just see what i'll do..
i'll just see what i'll do..
Current project: http://www.mmtycoon.eu
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: how should i do this?
What was wrong with what I said? Did it not make sense?
The indelible lord of tl;dr