Weapons/Items/Attribute Tables or Databases?

I have two interrelated questions to ask regarding efficient use of lists in a turn-based roleplaying game.

Tables vs Database
I wanted to get some feedback regarding the information tables or databases used in an RPG. RPG’s of course require massive lists of numbers and objects that interact with one another in combat, and I am not sure whether the use of SQLite databases would be more efficient than doing all the items in Lua tables.

Modularising
If I do the Lua tables, is it better to modularize the different lists in separate files or just in one big list? So let’s say for example I have the following:

Weapons
Armor
Magic
Items

and a few others. Keep each list in a separate table? Or does it matter? What has worked best for you? Thanks in advance. :slight_smile: [import]uid: 153366 topic_id: 30719 reply_id: 330719[/import]

I don’t know in terms of efficiency, but in terms of keeping your sanity, go with a database solution.

But, in terms of efficiency *and* sanity I’d go with separate tables for the objects. Just from those four examples I think you’d have as many unique columns for each one as you’d have duplicate columns.

I’m not a DBA and don’t go “all the way” in terms of normalization, but separating unlike things is often a good idea.

Jay [import]uid: 9440 topic_id: 30719 reply_id: 123048[/import]

Table VS Database
Well, just to make sure you understand, a Lua table is an object in memory… like an array, string or any other variable. SQLite DB is a physical(in a sense) file on the devices drive. The only way it would make sense to ask to use 1 or the other,in my opinion, is should you hold the data values in memory during game play or if you should just read/write to the DB every time you need those values. In that situation for performance reason holding the values in memory via a table is better.

The thing is for anything that will persist across different sessions you would want to write the table values to the DB(or some other file where you can reaccess them, such as just a text file holding a json dictionary).

Basically comes down to using Lua tables during gameplay and using the DB for saving the game data.

Modularising
Seperate lists, really. Lua tables are incredibly versatile but in cases like you are mentioning i try to format them to be similar in structure to a SQL db table, meaning kind of fixed fields that line up great. I’m assuming with all of the things you want to track that your Blade of Carnage weapon isn’t going to use the same data fields/types as your Cheese of Healing item. Also, there will be plenty of times where you may want to iterate over just your weapons. If everything is lumped together you would need to iterate over it all which is wasted processing power.

I hope that makes sense.

Also, you could also do tables of tables, so you have master table with subtables of your items but probably isn’t much benefit for you(ie masterTable.weapons[0].damage vs weapons[0].damage).

[import]uid: 147305 topic_id: 30719 reply_id: 123049[/import]

Table VS Database
I interpreted the questions as, should I just put all my into info a Lua table in my source code, or should I put it in a database and then read it in when I need it. I went with the latter, in which case you’re probably going to load it into a table for use at that point.

In my app Horse Crazy! I have all the horses and tack in a database and only load what I’m using at that point. And I update the database in real time – when someone drags a saddle onto the Friesian, for example, I add a row to a table that ties the saddle and the horse to each other. When they drag it off, I delete that row. So I really don’t do any “load at beginning, save at end” kinds of things.

In my Adventure Game Machine (long-term hobby project) I do the same thing – only load the location details of the current room and the items that are in that location. If an item is picked up or dropped the record for that object is updated at that point.

Depending on how much “action” is taking place on the screen, realtime updating may work fine. For a fast-paced arcade game? Maybe not. :slight_smile:

Jay
Modularising
[import]uid: 9440 topic_id: 30719 reply_id: 123058[/import]

I don’t know in terms of efficiency, but in terms of keeping your sanity, go with a database solution.

But, in terms of efficiency *and* sanity I’d go with separate tables for the objects. Just from those four examples I think you’d have as many unique columns for each one as you’d have duplicate columns.

I’m not a DBA and don’t go “all the way” in terms of normalization, but separating unlike things is often a good idea.

Jay [import]uid: 9440 topic_id: 30719 reply_id: 123048[/import]

Table VS Database
Well, just to make sure you understand, a Lua table is an object in memory… like an array, string or any other variable. SQLite DB is a physical(in a sense) file on the devices drive. The only way it would make sense to ask to use 1 or the other,in my opinion, is should you hold the data values in memory during game play or if you should just read/write to the DB every time you need those values. In that situation for performance reason holding the values in memory via a table is better.

The thing is for anything that will persist across different sessions you would want to write the table values to the DB(or some other file where you can reaccess them, such as just a text file holding a json dictionary).

Basically comes down to using Lua tables during gameplay and using the DB for saving the game data.

Modularising
Seperate lists, really. Lua tables are incredibly versatile but in cases like you are mentioning i try to format them to be similar in structure to a SQL db table, meaning kind of fixed fields that line up great. I’m assuming with all of the things you want to track that your Blade of Carnage weapon isn’t going to use the same data fields/types as your Cheese of Healing item. Also, there will be plenty of times where you may want to iterate over just your weapons. If everything is lumped together you would need to iterate over it all which is wasted processing power.

I hope that makes sense.

Also, you could also do tables of tables, so you have master table with subtables of your items but probably isn’t much benefit for you(ie masterTable.weapons[0].damage vs weapons[0].damage).

[import]uid: 147305 topic_id: 30719 reply_id: 123049[/import]

Table VS Database
I interpreted the questions as, should I just put all my into info a Lua table in my source code, or should I put it in a database and then read it in when I need it. I went with the latter, in which case you’re probably going to load it into a table for use at that point.

In my app Horse Crazy! I have all the horses and tack in a database and only load what I’m using at that point. And I update the database in real time – when someone drags a saddle onto the Friesian, for example, I add a row to a table that ties the saddle and the horse to each other. When they drag it off, I delete that row. So I really don’t do any “load at beginning, save at end” kinds of things.

In my Adventure Game Machine (long-term hobby project) I do the same thing – only load the location details of the current room and the items that are in that location. If an item is picked up or dropped the record for that object is updated at that point.

Depending on how much “action” is taking place on the screen, realtime updating may work fine. For a fast-paced arcade game? Maybe not. :slight_smile:

Jay
Modularising
[import]uid: 9440 topic_id: 30719 reply_id: 123058[/import]