What's better? Tables or attributes

I have a pretty big game that I'm about to start coding once the art is finished. There is going to be a lot of data in the game and I want to have it using the most efficient way. So far:

tables:
I have no clue how to use them.

Attributes:
I know how to use them.
It seems like my code would start getting messy with so many.
Easy.

Which should I use? Can someone give me some knowledge of table? Thanks

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271

    Tables. Easy. Tables are essentially attributes listed in row/column format. With tables you can dynamically write or call to a specific cell, search for a specific term or variable, and much more. It's much more efficient too. There are dozens of videos on tables on YouTube. I'd recommend searching up GameSalad Table Tutorials and several should pop up.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Tables are very easy to use once you get the hang of them. I have a tutorial below for creating checkpoints using tables. It's not a table tutorial specifically but its a pretty simple introduction to tables if you're interested.

  • ArmellineArmelline Member, PRO Posts: 5,331
    edited June 2016

    I'm going to buck the trend here.

    If you have lots of information to store, tables is probably the way to go. They make managing lots of data easier. Tables are also best for things like level complete status, or recording how many stars per level.

    If you have only a handful of bits of information to store, perhaps less than 20, and particularly if they're disparate, use attributes. I'll never put music on/off status or things like that in a table, unless I have to make a table anyway.

    Tables use more overhead than attributes, and are more difficult to reference individual, static ones. Attributes can have values constrained to them, tables can not (properly). Overall, attributes are less flexible, though.

    In reality, you'll need a hefty mix of both. Each have a place, but people often recommend tables for tasks attributes would be better for. Let's look at two examples:

    • I'm building a database of levels. For each level, I want to record the fastest time it has been completed in, the number of stars earned, and if they found the secret bonus. I have 100 levels. Managing this in attributes would be a complete nightmare. It would be impractical to say the least. Tables are the obvious choice here.

    • I've made a game and need to store the following bits of information: The game mode selected, the name of the player, the costume he's chosen for the character, the current enemy difficult (which increments by a random amount each level), if music is on/off, if sound fx are on/off. A lot of people would just make a table to store this, but that would actually be more demanding on the game and more difficult to reference each one (you're having to use the Change Table Value behaviour each time you change one, for one thing). I'd recommend Attributes as the best option here.

    A lot of people default to tables for everything, but I've always found that a bit silly. Attributes have a very valuable place. Tables shouldn't be the go-to, they should be what's used when attributes aren't sufficient - either due to number, or the need to dynamically reference them.

    You'll almost certainly be best served by a mix of attributes and tables.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271

    @Armelline .....you little rebel. :P

    But I agree.

  • YeezyHypeBeastYeezyHypeBeast Member Posts: 60
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited June 2016

    Just keep in mind that writing TableCellValue(game.table name, 1, 2) or TableCellValue(game.table name, 3, TableColNumber(game.table name, "health")) throughout your code can get tedious

  • YeezyHypeBeastYeezyHypeBeast Member Posts: 60

    @KevinCross okay thanks for the tip

  • colandercolander Member Posts: 1,610

    Generally I use attributes which store information which is only needed in the current session of play. Any information which is required next time the game is played I store in a table, things like high scores, etc.

  • AdrenalineAdrenaline Member Posts: 523

    @colander said:
    Generally I use attributes which store information which is only needed in the current session of play. Any information which is required next time the game is played I store in a table, things like high scores, etc.

    Nice, I like that guideline. Simple and helpful.

Sign In or Register to comment.