Tables Functions
I've been watching @Braydon_SFX's videos on tables which are awesome, but I find I'm wondering about all the possible applications of the various tables functions besides what he covers in the videos. I thought perhaps it would be great to either have people share the way they have used each table function and/or post a simple template with your specific use of the tables. I know there are probably some really awesome ways other members have thought of that no one else is aware of so I hope you will share your knowledge and thinking. I would include a template but I'm not a GS ACE just yet! And I really haven't utilized tables as I have a very basic understanding of them. Hence the thread on tables Anyway I definitely would like to hear any and all thoughts for all of the below:
tablecellvalue
tablecolcount
tablecolnumber
tablecolsum
tablemergevalues
tablerowcount
tablerownumber
tablesearch
Comments
I'll try and give a very basic idea of how I use these functions in almost every project.
tableCellValue: I use this function in rules to detect if a value is a certain amount. Think of this as checking an attribute, because that's basically what it is. Instead of creating an attribute, I can create a table and put all of my generic values in there. It saves space and is easier to edit. I use this function a lot to evaluate single table cells. I also use it a lot with the Display Text Behavior as a quick debugging assistant.
tableColCount: The use of this function is to detect how many columns are in a table. This can be helpful in trivia games, for example, when you're checking to see if the user has gone through all of the questions.
tableColNumber: I don't use this much at all, but its use is to find the column that contains a certain key or name. For example, say you create a table with 100 columns and you want to reference col 79 frequently in your game. You name that column "frequent" and continue on with development. After a while, you forget which column you stored that value in, so you can use this function (and search for "frequent") to automatically find that column. Again, I don't use this function much at all so I don't have many more practical uses for it.
tableColSum: Like the previous function, I use this on occasion but it's pretty rare. You can plug in a range of columns (and this is where colCount could come in handy) and you can get the sum of those cells.
tableMergeValues: This function is extremely powerful and I use it a lot. This function takes a range of cells and merges them together so you can evaluate them with ease. Before this function, we had to manually plug in each cell like this: tableCellValue(Table1,1,1)..tableCellValue(Table1,2,1)..tableCellValue(Table1,3,1). That entire expression grabs 3 cells and merges them together. It's messy. I use the tableMergeValues function mainly for word games and sometimes for debugging (to see what's currently active in my table). I use this function in almost every project.
tableRowCount: This function is exactly like tableColCount except that it is used for rows instead of columns. I use this a lot in table expressions.
tableRowNumber: Again, this is just like the colNumber function. Not much else to say about this function.
tableSearch: This is probably the function I use most in my projects. TableCellValue is probably the second most used. This function is the most powerful table function. It allows you to search a table, as the name suggests. The beauty of this function is that you can plug in various other table functions to get a wide search range. For example, I usually use the rowCount or colCount function in conjunction with this function. While there are numerous uses for this function, I use it to search a dictionary table in my word games - I check to see if the user-entered word is a real word. If the function returns a certain value, I know that the word is real and I can continue to reward the player with points, health, etc.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Nicely laid out, @Braydon_SFX.
I was going to write something about tableMergeValues but you've explained it so I won't repeat you. Suffice to say it's quite useful!
I've lost track of the thread where this was posted but these are the original descriptions of the functions from the GS team (attached).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Awesome thanks a lot @Braydon_SFX and @tatiang
@Braydon_SFX can you let me know if I'm understanding this correctly? So in your basic word game template for the round rules actor's constrain behavior, instead of inputting tablecellvalue x 5 times I can use tablemergevalue correct? That could merge all the letters together so that when written to the typed table they would be detected by the answer table?
@dreichelt - Yes, that's the general idea. It depends on the type of game, obviously, but that's one example.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
The other benefit for tableMergeValues is that it allows you to take table data and convert it to a text string for use with the even more powerful text functions such as textSubStr().
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang what do you mean by text string? And what would some common uses of creating a text string be using tablemergevalue? What's the benefit in other words?
I realized I overlooked some table behaviors.
when and why would you use these? Application examples?
Copytable
Loopovertable
Here's a good example. Let's say you have a keyboard and your user is typing some words. Let's also say that you want to have a Delete or Backspace button to delete the most recent entered key. How would you do that? Well, you can use the table merge values to merge all of the letters, use a different text function to see how many characters are in this string, then use the subString function to locate and delete the most recent entered letter. While you can use each function individually, using them together increases their power.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Yes, what @Braydon_SFX said. I posted a custom keyboard project a while back and that's exactly how I did it.
This copies the entire contents of one table to another existing table. The best use of this is to backup a "master" table before altering it. Let's say you wanted to choose random rows to spawn actors with certain positions/values/etc. Each time through, you choose a random row, spawn an actor, and then delete that row so it isn't duplicated later. But you also want the player to be able to reset the game. So you first copy the master table to a "working" table and use that working table in all of your rules. When you need to reset everything, you copy the master table to the working table again, thereby overwriting it.
Loops are great if you're searching for something, calculating something, or needing to do something over and over. If you need to know the frequency of a certain value in a table column, you could make a REALLY long expression or you could Loop over Table with a rule to check if tableCellValue(tableName,self.whichRow,1)="somevalue" and if so, Change Attribute game.frequency to game.frequency+1 inside of it and the loop index set to self.whichRow, an integer. That will very quickly calculate the frequency.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you @tatiang @Braydon_SFX this is very helpful. I can't think of an instance where I will need some of these behaviors but I can practice using them in the mean time.
@Braydon_SFX ok I have another question about your basic word game template. So when I go into the round rules actor and take out the code in the constrain and switch it for the tablemergevalue, when I preview, the only letter that displays is the first one I type. I'm currently seeing how to switch out the coding in the constrain behavior of this actor that is a long string of code in order to get the benefit of the shorter tablemergevalue code...
@Braydon_SFX in other words I'm confused as to where I can implement the tablemergevalue so that I can do away with the long code you have in the round rules actor in the constrain behavior. I thought I understood but then reality hit me hard hahaha
facebook.com/photo.php?fbid=10155129263825282&set=a.10155129263740282.1073741833.878545281&type=3&theaterVisuals really help me understand. This is a visual representation as I understand it of @Braydon_SFX basic word game template.
It may just be me but I can't view that image.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang haha because I'm trying to figure out how to have it in the post atm lol
I didn't know how frustrating it would be to try adding a picture in a post
I can only figure out how to have a link so far...
@dreichelt Pro members can embed images and other files. You may need to upload it to a file-sharing site and then post the link here.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang haha I knew I had added pictures before with out this problem. Yeah my pro just ran out recently so I need to upgrade soon.
Just upgraded mine! Still waiting for the Studica verification, though.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Pay full price and get it instant!
Fortuna Infortuna Forti Una
Hah!
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Ok at least I have a link to it. @tatiang here's what I was referring to. Make sense? @Braydon_SFX make sense? I tried to make it clear. Seeing this really helped me better understand the coding as I tend to be much more visual. Looking at my visual representation there are a few mistakes or unclear items but I think it makes sense mostly. I'll have to fix those later.
s4.postimg.org/g2pzms025/Screen_Shot_2015_02_03_at_1_40_59_PM.png
@dreichelt - Right. I think you're basing that image off of my word game tutorial. Keep in mind that I was showing a 'simple' way to accomplish those things. There are much better ways to do things depending on the type of word game you're making.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Sure thing. Same with all the templates; sure they are a good start for a game but you wouldn't want to necessarily publish them as is since they can be greatly improved. I just made this to ensure I understood everything you were doing in the video. Once I saw it laid out like this it was like seeing how a musical instrument was plugged in and all the wiring that goes into that.
Even your simple word game video took me 20 views until I got everything. Then I made this visual to see if I really understood why and how you were doing everything.
I wish I had the wherewithal to organize my thoughts visually like that.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I'm working on a game that cut off the screen and filling with boxes to block enemies in a tiny space. When it reaches at 80% to pass other lvl. So i wonder if i can divide the screen into cells and every time my main actor passes one cell it's possible to spawn a box. Or even when i draw a square to fill it with boxes if the enemy is not inside that square.
Or maybe someone knows another method.
@pitikarmol, consider starting a new thread with your question. It's buried in someone else's thread on another topic and may get passed over.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
ok i will thanks.
tableRowNumber can be useful if you add and delete rows in a table. Since you can't add/delete columns, the tableColNumber is not as useful.
tableColSum is useful if you have stats you need to add together. Say you have a character that has armor, helmet, gloves, boots, etc and each gives its own bonus to defense. Since you can have only one of each item, you can replace the row data for that item and take the sum for your total defense.
Put both of those together and you can do something like ChangeCellValue for your boots. To get the boots row is found in tableRowNumber("StatsTable", "boots").
Or if you make it dynamic and reduce you logic, you can do things like
Pick up an item for slot X ("boots", "Helmet", "Shield", etc), equip it and change stat values in table "StatsTable" for row X ("boots", "Helmet", "Shield", etc)
@CodeMonkey wow that sounds like a really cool way to use those table functions. I'm going to come back and read your post a few dozen times so that I actually understand it all lol.