Tell Us About Tables
carlblanchet
Member Posts: 755
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!!
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!!
Comments
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!
MH
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?
Ex: sum, average, lowest, highest value of a row/column?
If not, does anyone know if gs plans on adding these in anytime soon?
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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
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?
I'm pretty sure the limit is still set to 50.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx