Tell Us About Tables

carlblanchetcarlblanchet Member Posts: 755
edited July 2012 in Working with GS (Mac)
Hello everyone!

I have now gotten to a point that I need to use tables in my games, but I do not know much about them, nor can I find many videos with what I am looking for...

Please, if you have the time, I (and others who might be reading this) would really appreciate it if you could write something about tables and what they can be used for, that you think would be informative to others learning about tables, and including how to do it would be even more appreciated!!

Thank you so much! Can't wait to hear what you all have to say!! :D

Comments

  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    Check out TSB's tutorials at www.gshelper.com
  • IsabelleKIsabelleK Member, Sous Chef Posts: 2,807
    Yeah TSB's tutorials are great! Tables are great too - I would marry them, if they could cook :P
  • MotherHooseMotherHoose Member Posts: 2,456
    tables are wonderful!

    think of them as a place to store/access/update lots of attributes
    (the tables themselves are gameAttributes assets)

    the format of any table is .csv (CommaSeparatedValues)
    row are separated by lines of values (a newLine = a new row)
    columns are separated by commas (a comma after value = a new column for next value)
    files with the extension .csv open with spreadsheets apps; database apps; textEdit apps

    you add tables to your game in Home: Tables
    GS tables have column specific dataStorage types
    you click the small ↕ at the top of the column
    and select the type of data you want to store
    (Text; Integer; Real; Angle; Boolean; Angle … as you do when you add an Attribute)
    (index is not selectable … Indices in a table are the row,column point)
    you can label a row or a column …
    click and type in the blanks to L of the row# … or above the column

    you can write-in the values of the cells for row,column when you make the table
    … or during gameDevelopment make changes to a table from Creator
    or you can have the computer write-in/change values during runTime
    you can import a table (a .csv file) and export your tables

    the calls for values in a table:
    are in Functions list in Expression Editor:
    -tableCellValue(table,row,col)
    -tableColCount(table)
    -tableRowCount(table)
    …always select the table from Game list
    -row or column can be:
    --the row # from the table;
    --a game/scene/actor Attribute … selected
    --the label … labels are typed within parentheses ex: "image"; "Xposition"; "Y1"

    good to name your tables uniquely and prefix with a reminder that it's a table
    ex: TB-enemy; tb-enemy; *enemy

    okay that seems like more work for you to do
    but, how to make tables is easy to learn …
    learning tables … will save lots of work/time/frustration in developing a game

    and, when your game loads
    the tables are a written in RAM … just a small collection of bits/bytes
    …so resourceUsage for assets are minuscule
    and, computers handle that processing very rapidly
    … so loadTime is fast
    and that batch of data is so easily accessed and implemented

    tables behaviors:

    -Add/removeRow:
    … at beginning (row 1)
    … at end (last row)
    … at index (an attribute: ex: myRow)

    -Change Table Value
    - row: number or attribute or label
    - column: number or attribute or label
    - value: number or attribute
    (and you can add more Column to change)

    -Copy Table
    - to a blank table (you must add the blankTable first)
    --this is good to do for runTime values that are changed
    and, with tables it is easy to make random function really random
    … changeAttribute: currentRow To: tableCellValue(table,row,col)
    (actors use currentRow to change their Attributes)
    EX: tableCellValue(TB-myTable,random(1,tableRowCount(TB-myTable),1)
    Add/Remove Row: Remove row … at index … Expression: currentRow

    -Save Table
    -save the table with the runTime changes
    -when game is reopened change the game/actors attributes to those tableCellValues
    all kinds of things like level; highScore; itemsCollected; timeElapsed; … etc.

    that is powerful functionality for so little learning time!

    tables will also eliminate a lot of actor's rules/behaviors
    so eventually you end up spending less time coding
    EX: working with a gameAttribute for SceneName or scene#
    -changeAttribute: self.Position.X To: tableCellValue(TB-myTable,game.scene#,"X")
    and same for Y; images; W; H; rotation; etc.
    NOTE: when using SceneName make attribute text type … and label tables rows
    using that text that is in the attribute … do not enclose in parentheses

    watch @Tshirtbooth videos … all of them and often! and download his demos!

    make a folder called Sandbox
    make some tablesProjects
    rebuild TSB's demos
    play around with everything … using lots of display texts … so you see changes
    spawn some things … using table values for position
    changeAttribute: self.Image using a list of image names
    set gameAttribute values with tables
    EX: max#enemies

    have lots of fun … and you will think tables are wonderful!

    image MH
  • thelogobarthelogobar Member Posts: 93
    I'm just entering the world of tables, it really opens up lots of possibilities.
  • carlblanchetcarlblanchet Member Posts: 755
    @MotherHoose Thank you so much for the great information! :)
  • Hapy00Hapy00 Member Posts: 16
    Sorry, noob question on Tables and GS...

    I have a an Attribute that is looking up a Table, and it is asking for:

    "tableCellValue(game.TB My Table, game.Attribute+1,2)

    Basically I want to use the Attribute to count up every time this function is called. So, for the row I am putting in "Attribute+1". This however does not seem to work. Any idea why not or am I doing something wrong?
  • ironDanironDan Member Posts: 148
    If you are using game.attribute+1 then its not going to count up +1 its only going to give you the row you are seeking +1. So for example if your game. attribute is an index or integer and the value is 5 and you say game.attribute+1 it will go to row 6 of that table value and thats it. You will need to be more specific on what the rule is trying to accomplish for people to be able to help you.
  • FloridaGamesFloridaGames Member Posts: 328
    edited August 2012
    I dont believe there is, but can you put functions in a table like you can in ms excel?
    Ex: sum, average, lowest, highest value of a row/column?
    If not, does anyone know if gs plans on adding these in anytime soon?
  • Nooby here, im not getting the who tables thing.. Can anyone please tell me why it would be benificial to use tables and can i get an example of a popular game that uses tables, or a game genre that would use tables.
  • MayhemmmartyMayhemmmarty Member, PRO Posts: 39
    @jcarvgames@gmail.com I would imagine every game uses tables. The best basic example of using tables would probably be for saving high scores. There are many videos on youtube. Search for "Gamesalad Tables" and a lot of good examples show up.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Check out our table tutorials on ghelper.com
  • quantumsheepquantumsheep Member Posts: 8,188
    Nooby here, im not getting the who tables thing.. Can anyone please tell me why it would be benificial to use tables and can i get an example of a popular game that uses tables, or a game genre that would use tables.
    They really are very powerful. Here's an example:

    I have an enemy actor. I want him to look different for each level.

    I have 100 levels.

    Now, without tables, you'd probably have to open up the actor and have a rule that says:

    If attribute level = 1
    Change self.image to enemylevel1.png

    then another rule that says:

    If attribute level = 2
    Change self.image to enemylevel2.png

    You'd then have to do that another 98 times, once for each level. Which would make your enemy 'actor' very heavy, and probably impact the performance of your game.

    Also, it'd be a nightmare to try and change/fix something in that actor!

    -------------------------------------------------------------


    So let's try that same thing but with a table. Remember, the idea is that your enemy will use a different image for each level, and there are 100 levels.


    Every time you finish a level, you could increase the 'game.level' attribute by 1. So if you beat level 1, the level attribute would increase by one to 2.

    Make a table - let's call it TB_enemy (I like to name them with TB at the front to seperate it from attributes in the list).

    Define the first column as a 'text' type.

    In the first five rows, in column 1, put in the name of your enemy image. If you have 100 enemies, you might call the images enemy1, enemy2, enemy3, enemy4, enemy5 and so on!


    Now, in your enemy actor you'd use just one behaviour:

    Constrain self.image to tablecellvalue (game.TB_enemy,game.level,1)..".png"

    One behaviour instead of 100 rules!


    What does this do?

    Well, it uses the value it finds in your table (that's the game.TB_enemy bit).

    The level number tells the game which row to look at.

    Then the first column will dictate the text to use.

    So it will read the text 'enemy1' for level 1, 'enemy2' for level 2 and so on and so forth.

    The ..".png" just tells the game to use an image formed from the word 'enemy' and put a .png the end to make it an image.

    Now, imagine how much easier it will be fill 100 rows of text in a table than putting in 100 rules in an actor.




    So there's just one way of looking at tables and their advantages.

    I use a table for my enemies in my next game. It has 100 levels, and I use tables to determine an enemy's animation images, size in x and y, movement speed, colour, hit points etc etc.

    It means I can have my enemies do a huge variety of things with just one actor and a small amount of rules/behaviours.

    Hope that helps somehow!

    QS =D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • slowcutslowcut Member, PRO Posts: 164
    This is a very good description how to use tables, and what's the advantage of tables,

    But in the case of changing the enemy image via tables it is also possible to change it with one behavior and no table, as long as they named properly ( enemy1, enemy2, enemy3 etc) and refer logically to the levels

    If you want to stick with the constrain:

    constrain self.image to "enemy"..game.level

    But i would prefer a change behavior for the image change and trigger it at level start

    It is not necessary to put the ".png" in the expression anymore.

    But it always good to learn how to use tables and how they work and speed up the workflow and save ressources

  • What is the maximum number of individual tables that Gamesalad can support?

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @walterwoods@comcast.net said:
    What is the maximum number of individual tables that Gamesalad can support?

    I'm pretty sure the limit is still set to 50.

Sign In or Register to comment.