Display text not working?
3absh
Member Posts: 601
I'm trying to debug my game and I need to display a boolean attribute
so this is what I typed
"Fruit1Hit "..Fruit1Hit (the second part with no quotations is the attribute)
the result in preview mode should be
Fruit1Hit false
I get instead
Invalid Expression
I've tried it and it worked before but with integral attributes.
When I remove the part with the quotation marks I get False in preview
What do I have to do for the text to appear before the false statement?
Comments
I know I can make another display text behavior and locate it beside the display attribute but that would be inconvinent, I want to see if its possible to display both the text and the behavior under one command
I believe there is an issue doing this with booleans.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Correct. It won't work with a boolean. You could make a rule that says When game.Fruit1Hit is true, Display "Fruit1 True"; Otherwise Display "Fruit1 False" but I suspect you might prefer to use an integer in place of the boolean. Integers can serve the same purpose if you restrict their values to 0 or 1.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Agreed. I rarely use booleans.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Booleans seem to be working in a Display Text behavior. But they don't seem to work when you use the two dots for concatenation.
Correct. That's how they've always functioned.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
You should be able to get it to display as text with something like:
"Fruit1Hit "..((game.Fruit1Hit)and("true")or("false"))
I was playing around with that earlier and couldn't get it to work, @RThurman.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Hmm.... thats kinda frustrating! Another Lua bug?
I guess. You'd think that the logical operators would result in an integer value of 0 or 1 and then get converted back to strings, which theoretically should work with a Display Text behavior.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@RThurman, I did a little digging and it turns out that Lua stores boolean attributes as either the value true or the value false. They aren't converted to numerical values. So it makes sense why the Display Text behavior can't handle them... they aren't strings or numbers. Still would be handy though!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
In Lua you can't concatenate a boolean with a string just using
string .. boolean
.What you need is
string .. tostring(boolean)
which is a simple thing in regular Lua code, but not so simple when you need to apply it to an attribute since lua functions don't know anything about those.You can do it all with one complex line though: (Thanks to Armelline I believe)
'TrueFalse is ' .. (((yourbooleanattribute) == true) and ('true') or ('false'))
It was late when I answered last night and I didn't test it out much. But testing it now it works just fine. This works:
"Fruit1 "..(( self.Fruit1Hit )and("true")or("false"))
That is functionally equivalent to what I suggested above.
But I did not use the equality operator " ((yourbooleanattribute) == true) " since the boolean attribute will already evaluate to true or false based upon its value/state. I suppose its good to include the equality operation to make it explicit, but this works just as well:
'TrueFalse is '..((yourbooleanattribute)and('true')or('false'))
I used this method
Great solution! Glad its working for you!