GameSalad

Howdy, Stranger!

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

tableSearch(game.Table, "game.Attr. Answer 1", etc. -> Can I call an attribute in tableSearch?

JB makin' a gameJB makin' a game Posts: 22Member, BASIC
edited August 5 in Help Wanted

So I've been making a simple game to get me started on GameSalad and I'm starting to get the hang of the Tables and attributes, but I'm running into something that I can't seem to fix by myself.
In the screenshot above, you see the tables I'm using and an overview of the rules and attributes I'm working with.

As it says in the title and as you can see in the picture I added, I'm Changing Attribute: self.Attr. Row A1=Wrong to tableSearch(game.Tb. Wrong,"game.Attr. Answer 1","col",1,1,tableRowCount(game.Tb. Wrong),"exact").
Given all the lines that are written above it, the way I see it, this is supposed to happen:
self.Attr. Row A1=Wrong (which is an integer attr, the other attrs are text) should change to either 0 if the game.Attr. Answer 1 isn't in game.Tb. Wrong at all, or it'll show a rownumber which can range from 1 to 8, because it should correspond with the game.Attr. Answer 1 attribute.
However, it doesn't. I've created an instanced to display self.Attr. Row A1=Wrong to check it and it shows 0 all the time, whether game.Attr. Answer 1 is in Tb. Right or Tb. Wrong. As I said, I was expecting it to show random(1,8) if Answer 1 turned out to be (in table Tb.) Wrong. I want this rownumber in an attribute, because I have four answers in this game and only one of them should be 'Wrong'. So the code for answer 2 starts with a Numeric Expression:
if self.Attr. Row A1=Wrong >= 1
do [code for Answer 2 = Right]
else [code for Answer 2 = Right/Wrong]

My conclusion is that either the tableSearch() function doesn't allow you to call a game attribute as the string you're searching for (and I hope this is not the case, because I kinda liked the tableSearch() function up until now) or I'm not seeing something and perhaps you can help me. Since this is my second week on GameSalad, I'm guessing it's the latter ;)

Thanks in advance for anyone that took the time to read this and can point me in the right direction!

  • JB

PS. I guess it's important to mention that I've created an instance that displays the text from game.Attr. Answer 1 and it works the way it should. It shows random words from either (also random) table Tb. Right or Tb. Wrong.
PPS. I'm aware of what the Save Table function does and I got my table-copy ready to overwrite all the (saved) changes that are made between the start and end of the game. Secondly, I'll start working on Add/Remove Row stuff to make sure words don't get used twice. However, I feel that I first have to work this question out, before starting on new rules and conditions.

Comments

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

    My conclusion is that either the tableSearch() function doesn't allow you to call a game attribute as the string you're searching for

    You can use a text attribute for the search string.

    Here's a demo.

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

  • JB makin' a gameJB makin' a game Posts: 22Member, BASIC

    Ah, when using a text attribute in tableSearch, it doesn't have to be inside quotation marks.
    That actually sounds a little illogical to me, because the attribute represents a word/string of letters and those ought to be in quotation marks. However, you won't hear me complaining, because it's working now :)

    Thanks a lot!

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

    I think of attribute names as reserved words so they don't need to be in quotation marks. Also make you aren't typing in the name of the attribute... that won't work. You have to select them from the attribute browser / drop-down menu.

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

  • JB makin' a gameJB makin' a game Posts: 22Member, BASIC

    Yeah, I noticed, thanks!

    Also, I was wondering... I created the game functions for all four answers in one actor and display the answers with another and that's pretty much the entire game as it is right now. It's a lot of code in one actor, but I'm new here and had to be sure that the code was executed in a chronological order. And it's working, so I'm happy. However, is it good practice to put a lot of code in one actor? The code creates these functions:

    • Answer 1-4 are random Right/Wrong
    • They are distributed randomly over 4 instances (otherwise Answer 2 is always wrong for example)
    • When a word is displayed, it gets removed from the table it was in, so it doesn't show the same word in any of the other answers or further along this level of the game.

    Would it be better to create separate actors for the game functions or Answer 1, Answer 2, etc.? Or is it fine the way it is?
    Oh, and I if need a Table copy, it seems that selecting the table you wanna copy and just press Ctrl C, Ctrl V doesn't do the trick. Is there a way to select a table and create a copy of the entire table? Because in a few months, tables Right and Wrong should have hundreds of different words and I don't wanna typ every word I add to a table double for my table copy.
    Last question: is a table that uses over a 1000 rows, perhaps even 10.000 rows (to select a word as random as possible and you don't see the same words every time you start up the game) a good practice? Or should I spread the words over multiple tables and add code to search in multiple tables?

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

    I would typically use a single actor to create the answer rules and then copy it within a scene to make separate instances for each answer "button."

    You can copy a table (at least in the Mac version) during run time but otherwise, the only way is to export the table to Excel, etc. and then import a separate copy of that data.

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

  • JB makin' a gameJB makin' a game Posts: 22Member, BASIC

    Another tableSearch question...
    I've created a table with a boolean column. When playing the game, it sets the boolean cell to true if an answer is correct. When the game is finished, I want the player to have an option to learn from his mistakes and remake the questions (s)he answered incorrectly. I figured it'd be the easiest way to use tableSearch to find the row in which the boolean is still false, store that value in an index-attribute rowIncorrectAnswer1 or whatever and then change the cell value of that false boolean cell to true and repeat the process, until attr.rowIncorrectAnswer turns out to be 0.

    Now I wonder what I should put in the tableSearch function to look for a false boolean cell. Is it:
    tableSearch(game.Tb.userAnswers, 0, "col", 1, 1, tableRowCount(game.Tb.UserAnswers), "exact")
    or does the zero have to be false, "false", "0" or something else. Hopefully it is actually possible, but I guess it should be.

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

    @JB makin' a game said:
    Now I wonder what I should put in the tableSearch function to look for a false boolean cell. Is it:
    tableSearch(game.Tb.userAnswers, 0, "col", 1, 1, tableRowCount(game.Tb.UserAnswers), "exact")
    or does the zero have to be false, "false", "0" or something else. Hopefully it is actually possible, but I guess it should be.

    It's easy enough to test but I suspect you'll need to put this as the search key:

    "0"

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

  • JB makin' a gameJB makin' a game Posts: 22Member, BASIC

    Thanks. Tested it and just 0 works, with or without quotation marks. Typing false, with or without quotation marks, doesn't.
    Also, I used to typ my Change Boolean Attr as true/false, until I found out you could just typ 0 and 1. Now I got 'em mixed up all over my code. I'm not too worried that I can't keep track of stuff, but I was just wondering if it matters for the engine if I use false and 0 in the same set of rules, loops, etc.

  • AlchimiaStudiosAlchimiaStudios Posts: 980Member, PRO

    @JB makin' a game said:
    Thanks. Tested it and just 0 works, with or without quotation marks. Typing false, with or without quotation marks, doesn't.
    Also, I used to typ my Change Boolean Attr as true/false, until I found out you could just typ 0 and 1. Now I got 'em mixed up all over my code. I'm not too worried that I can't keep track of stuff, but I was just wondering if it matters for the engine if I use false and 0 in the same set of rules, loops, etc.

    Don’t think so, they’re pretty much interchangeable.

    Follow us: Twitter - Website

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

    @JB makin' a game said:
    Thanks. Tested it and just 0 works, with or without quotation marks. Typing false, with or without quotation marks, doesn't.
    Also, I used to typ my Change Boolean Attr as true/false, until I found out you could just typ 0 and 1. Now I got 'em mixed up all over my code. I'm not too worried that I can't keep track of stuff, but I was just wondering if it matters for the engine if I use false and 0 in the same set of rules, loops, etc.

    No, it doesn't matter. If you prefer, you can just use an integer whenever you need a boolean. It can just as easily be 0 or 1. And you can use the expression 1-game.attribute to toggle the value since 1-0 becomes 1 and 1-1 becomes 0.

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

Sign In or Register to comment.