Page 1 of 1
Players resources - how to store them
Posted: 14 January 2024, 13:49
by Hornir91
Hello.
I am currently developing a game in the studio and have a question.
How do you store players resources in the database?
Should I extend players table and add columns to store quantity of eg. "food" and "gold" tokens and in JS make just a visual representation based on these values or store every resource token in db as a independent record and then just assign playerId to them when player should receive one?
Re: Players resources - how to store them
Posted: 14 January 2024, 13:57
by RicardoRix
You could do it that way, if it's just a quantity, but otherwise I would create a new table. Personally speaking, I have a generic data table with player_id for this kind of thing. The framework also has a built-in 'global vars' which could be fudged for this too:
https://en.doc.boardgamearena.com/Main_ ... se_globals
For individual tokens that normally have ids: Usual is either : 1 table per kind of resource, or 1 table for all resources with a 'token_type' field.
However you like though, world is your oyster.
Re: Players resources - how to store them
Posted: 14 January 2024, 16:30
by Hornir91
Thank you for the answer

.
Actually I will stick with having one big table for tokens used in the game.
Re: Players resources - how to store them
Posted: 14 January 2024, 17:08
by RicardoRix
In the 'sharedcode' project there is a file called tokens.php. I believe that's the general idea for that - to have just 1 table for all tokens.
https://github.com/elaskavaia/bga-share ... er/modules
Re: Players resources - how to store them
Posted: 14 January 2024, 17:11
by LeSteffen
Here's what I do:
1. For game-wide values (e.g. turn number) I use the BGA framework's setGameStateValue()
2. For simple player-related variables I extend the player table
3. Everything else needs it's own DB table

Re: Players resources - how to store them
Posted: 15 January 2024, 08:02
by Tisaac
Hornir91 wrote: ↑14 January 2024, 13:49
Hello.
I am currently developing a game in the studio and have a question.
How do you store players resources in the database?
Should I extend players table and add columns to store quantity of eg. "food" and "gold" tokens and in JS make just a visual representation based on these values or store every resource token in db as a independent record and then just assign playerId to them when player should receive one?
Both approach are perfectly valid and i have used both in my games. The main criterion for me to decide is whether these tokens might be displayed somewhere outside of these reserves. If it's just some kind of "money", then sure you can put them in player db. But if like agricola, meeples Can be placed on your player board, on next action space, on cards, etc, then it's much easier to just store them in a "token" db (i use my own augmented version or deck for that)