GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tables Functions

motorcycle boymotorcycle boy Posts: 429Member
edited February 2015 in Community Tutorials

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

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef

    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

  • motorcycle boymotorcycle boy Posts: 429Member

    Awesome thanks a lot @Braydon_SFX and @tatiang :smiley:

  • motorcycle boymotorcycle boy Posts: 429Member

    @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?

  • Braydon_SFXBraydon_SFX Posts: 8,959Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee

    @dreichelt - Yes, that's the general idea. It depends on the type of game, obviously, but that's one example.

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef

    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

  • motorcycle boymotorcycle boy Posts: 429Member

    @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?

  • motorcycle boymotorcycle boy Posts: 429Member

    I realized I overlooked some table behaviors.
    when and why would you use these? Application examples?

    Copytable
    Loopovertable

  • Braydon_SFXBraydon_SFX Posts: 8,959Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee

    @dreichelt said:
    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?

    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.

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef
    edited February 2015

    Yes, what @Braydon_SFX said. I posted a custom keyboard project a while back and that's exactly how I did it.

    Copy table

    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.

    Loop over table

    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

  • motorcycle boymotorcycle boy Posts: 429Member

    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.

  • motorcycle boymotorcycle boy Posts: 429Member

    @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...

  • motorcycle boymotorcycle boy Posts: 429Member
    edited February 2015

    @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

  • motorcycle boymotorcycle boy Posts: 429Member
    edited February 2015

    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.

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef

    It may just be me but I can't view that image.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • motorcycle boymotorcycle boy Posts: 429Member
    edited February 2015

    @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 :neutral:
    I can only figure out how to have a link so far...

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef

    @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

  • motorcycle boymotorcycle boy Posts: 429Member

    @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.

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef

    Just upgraded mine! :) Still waiting for the Studica verification, though.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • LovejoyLovejoy Posts: 2,078Member

    @tatiang said:
    Just upgraded mine! :) Still waiting for the Studica verification, though.

    Pay full price and get it instant! :p

    Fortuna Infortuna Forti Una

  • Braydon_SFXBraydon_SFX Posts: 8,959Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee

    @Lovejoy said:
    Pay full price and get it instant! :p

    Hah!

  • motorcycle boymotorcycle boy Posts: 429Member
    edited February 2015

    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

  • Braydon_SFXBraydon_SFX Posts: 8,959Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee

    @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.

  • motorcycle boymotorcycle boy Posts: 429Member
    edited February 2015

    @Braydon_SFX said:
    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.

    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.

  • tatiangtatiang Posts: 11,766Member, Sous Chef, PRO, Senior Sous-Chef
    edited February 2015

    I wish I had the wherewithal to organize my thoughts visually like that. :D

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • pitikarmolpitikarmol Posts: 12Member

    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.

  • jamie_cjamie_c ImagineLabs.rocks Posts: 5,539Member

    @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.

  • pitikarmolpitikarmol Posts: 12Member

    ok i will thanks.

  • CodeMonkeyCodeMonkey Posts: 1,803Head Chef, Member, PRO

    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)

  • motorcycle boymotorcycle boy Posts: 429Member

    @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.

Sign In or Register to comment.