Display text with expression fails with booleans

I'm trying to add some text in front of an attribute value using an expression along the lines of "text: "game.attribute

This works perfectly when the attribute is an integer or something similar, but when the attribute is a boolean this results in an invalid expression. Does gamesalad really not support adding text and a boolean in an expression or am I doing something wrong?

Comments

  • JamieOneilJamieOneil Member Posts: 877
    You are not doing anything wrong, I don't know if it is a bug or what but there is an easy fix since booleans only have 2 values, true or false.

    If game.attribute = true then
    display text "text: true"
    else
    display text "text: false"
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2014

    Hi @imjustmike Yes, it's either a bug, an oversight or intended... (i.e not able to concatenate with a boolean in a Display Text behaviour)... you decide which! ;-)

    That's a really neat solution from @JamieOneil - a good workaround.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I remember black cloak explaining why this is but there is a reason for it.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    I remember black cloak explaining why this is but there is a reason for it.
    I'm all the more intrigued to know the reason now!! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @imjustmike -- you can make a Boolean into an integer "0" or "1" with the following expression:

    "text: "..((game.attribute)and(1)or(0))

    you can also turn a Boolean into text:

    "text: "..((game.attribute)and("true")or("false"))
  • BlackCloakGSBlackCloakGS Member, PRO Posts: 2,250
    The reason that the .. operator does not work with bool has to with our reliance on Lua for execution of expressions. We use Lua to execute the expression and in Lua the .. operator does not work with booleans.
  • imjustmikeimjustmike Member Posts: 450
    edited January 2014
    Thanks all, especially @jamieoneil and @RThurman for a workaround and @blackcloakGS for an explanation
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @imjustmike -- you can make a Boolean into an integer "0" or "1" with the following expression:

    "text: "..((game.attribute)and(1)or(0))

    you can also turn a Boolean into text:

    "text: "..((game.attribute)and("true")or("false"))
    This is awesome! Thanks, @RThurman.

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2014

    @BlackCloakGS
    The reason that the .. operator does not work with bool has to with our reliance on Lua for execution of expressions. We use Lua to execute the expression and in Lua the .. operator does not work with booleans.
    Thanks for the explanation, BC, appreciated. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @imjustmike -- You are welcome. Hope it works for you.

    @tatiang -- Boolean logic is its own universe. It sometimes seems (to me) to be counter intuitive, but it can be very useful.
  • eegameseegames Member, BASIC Posts: 1

    @RThurman said:
    @imjustmike -- you can make a Boolean into an integer "0" or "1" with the following expression:

    "text: "..((game.attribute)and(1)or(0))

    you can also turn a Boolean into text:

    "text: "..((game.attribute)and("true")or("false"))

    What is this, and how do I learn more? I can't find any reference to an and() or or() inside GameSalad, and I feel like would be really helpful in other uses.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @earl0000 said:

    @RThurman said:
    @imjustmike -- you can make a Boolean into an integer "0" or "1" with the following expression:

    "text: "..((game.attribute)and(1)or(0))

    you can also turn a Boolean into text:

    "text: "..((game.attribute)and("true")or("false"))

    What is this, and how do I learn more? I can't find any reference to an and() or or() inside GameSalad, and I feel like would be really helpful in other uses.

    Go to learn.gamesalad.com and see @Armelline tutorial learning to love the expression editor.

Sign In or Register to comment.