Display text not working?

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

  • 3absh3absh Member Posts: 601

    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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    I believe there is an issue doing this with booleans.

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

    @Lost_Oasis_Games said:
    I believe there is an issue doing this with booleans.

    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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    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.

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

    @RThurman said:
    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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    You should be able to get it to display as text with something like:
    "Fruit1Hit "..((game.Fruit1Hit)and("true")or("false"))

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

    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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Hmm.... thats kinda frustrating! Another Lua bug?

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

    @RThurman said:
    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

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

    @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

  • GeorgeGSGeorgeGS Member, PRO Posts: 478

    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'))

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @tatiang said:

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

    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"))

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @GeorgeGS said:
    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'))

    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'))

  • 3absh3absh Member Posts: 601

    I used this method

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Great solution! Glad its working for you!

Sign In or Register to comment.