3 Replies - 320 Views - Last Post: 11 January 2014 - 11:36 AM Rate Topic: -----

#1 Vasquez21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-January 14

Database issue, best solutions to store locations

Posted 10 January 2014 - 01:18 PM

Hi guys,

I am making browse-based game. I want to store my locations in database, and have two ideas how to do that:

1.
I have table in DB called "Locations" where I have standard fields like: name, description etc. and also:
move_N, move_S, move_E ,move_W - four fields which store id of other locations. If null, than I know there is no way in this direction.

2.
Like above I have table in DB called "Locations" but possible directions are stored in separate table. Every time player enters new location, I am quering this table to got possible directions.


From those two I prefer second option (because it gives me more options), but I am not sure if earching through all results in this table all the time will be best option?

Is This A Good Question/Topic? 0
  • +

Replies To: Database issue, best solutions to store locations

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9208
  • View blog
  • Posts: 34,589
  • Joined: 12-June 08

Re: Database issue, best solutions to store locations

Posted 10 January 2014 - 01:24 PM

Run that by again - what do you mean by "locations"? Is that a x,y point or something else?
Was This Post Helpful? 0
  • +
  • -

#3 Vasquez21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-January 14

Re: Database issue, best solutions to store locations

Posted 10 January 2014 - 05:31 PM

Locations are places where player can move his character.

So for example. Let's say our character is in "forest" (which id will be 1)
He can usually go in four direction. For example:
North - there is another Forest (id 2)
East - Mountains (id 3)
South - Desert (id 4)
West - Forest again (id 5)

And now in database I can have one table which will look something like this:
Locations: id_loc , name, move_n, move_e, move_s, move_w
and my entry for above example will be:
1, forest, 2, 3, 4, 5

or... i can store it in separate table then I will have table Locations
Location: id_loc, name
1, forest
and another table, let's call it "paths"
Paths: from, destination, direction
1, 2, N (from Location with id 1, to location with id 2 which is on North of it)
1, 3, E
1, 4, S
1, 5, W
if I want also to go back, I have to add:
2, 1, S (I came from N, so now have to go S)
3, 1, W
4, 1, N
5, 1, E
Was This Post Helpful? 0
  • +
  • -

#4 Vasquez21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-January 14

Re: Database issue, best solutions to store locations

Posted 11 January 2014 - 11:36 AM

Ok to clear everything more, I would make example with database.

Let's say I have 2 tables: one is called "locations" and have information about it, and other table is called "paths" and shows the ways which player can move from any location.

TABLE Locations:
id_location
name
description
etc.

TABLE Paths:
id_path
id_location (FK from Locations)
id_destination (FK id_location from Locations) - this is the possible way where player can move
directions (char, which tells me in which direction from curent location this locations exist)
etc.

And now for example:
LOCATIONS (id_location, name, description)
1, forest, just forest
2, desert, just desert
3, mountains, just mountains

PATHS (id_path, id_location, id_destination , directions)
1, 1, 2, N (which exactly show me, that when player is in forest (1) he can move to desert (2) if he will go North
2, 2, 1, S (and now exactly opposite, from desert, to forest if player will go South

My questions is, if this soulutions is ok, or maybe I should use other solutions to store my "map"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1