How to toggle a boolean attribute
Hairy_fat_back2
Member Posts: 2
Hello, I was just wondering how to toggle a Boolean variable in a table cell in game. Would I use a change table value behavior? If so how do I make it toggle true and false when I continuously press a button? Thanks for the help!
Comments
Yes, you can use a Change Table Value behavior. The most efficient way to do this is to use an integer in place of a boolean since booleans are binary (1=true, 0=false). If you change the cell value to 1 - tableCellValue(tableName,row,col), it will toggle the value between 0 and 1. This is because 1-0=1 and 1-1=0.
Please use descriptive thread titles (e.g. "How to toggle boolean attribute") so that people skimming thread titles can get a quick idea about what you're asking.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Sorry about the title, thanks so much for the reply!
Since it is a boolean, I find it easier to use the not() boolean operator. As in:
not(tableCellValue(table,row,col))
In addition to being a boolean value, a boolean can also be evaluated as both a text and a numerical value. So there are at least three ways to evaluate it in a rule. Attached is an example of using "not" and also three ways of forming a rule to evaluate a boolean table cell value.
not(not insightful), @RThurman.
Or is that not(not(insightful))?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
The second!
not(the first)!
Which reminds me of a story from college: my roommates threw a party in our apartment sophomore year (I wasn't there but...) and when the police were called and showed up, they asked for the tenants' names. The first roommate answered, "Michael Stewart the fourth." The second roommate answered, "Alex Thompkins the fourth." The third roommate answered, "Dennis Portman." The cop asked, "Are you also the fourth?" To which Dennis replied, "Not tonight, sir."
It's been a long work week already so forgive me for two not very funny comments in one post.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User