String concatenation

spacechimpspacechimp Member Posts: 9
edited November -1 in Working with GS (Mac)
Does anyone know a way to do string concatenation in Game Salad?

Example of what I want to do:
game.TextAttribute=game.TextAttribute + "some new text to be added"

I tried the above which did not work and tried comma separation too. Appending strings together seems like a pretty rudimentary operation and I would be surprised if GS cannot do this!

Comments

  • VmlwebVmlweb Member Posts: 427
    I don't think this is possible yet but it would sure be a great thing for lots of people.
  • rebumprebump Member Posts: 1,058
    Use two periods next to each other as the concat operator. However, strings are picky about spaces in them in certain situations. Sometimes you need to embed a string in an attribute and then concatenate the other strings/values with the attribute.

    Alot of times you will use "Display Text" on an actor to display some of its or the game's attributes. It is good to show a couple at a time sometimes (i.e. VelocityX and Velocity Y). Howerver, this will not work (currently):

    `game.Attribute1.." "..game.Attribute2`

    You would have to use a dash (instead of the space) or something to seperate out the two values since the string constant with the space in it won't be accepted in one of the expression ("e") boxes in the rules/attributes.

    You could define a string attribute and assign a space to it (I think I got this to work for me but not sure...and not in front of a Mac right now to re-verify...it may have gotten stripped though):

    `game.SpaceString = " "`

    (although, you will just enter a space in the attribute value area without the quotes)

    So then you can:
    `game.Attribute1..SpaceString..game.Attribute2`

    The following do work...

    No space allowed (currently) after the colon in the constant string when entered into an expression ("e") box:

    `"Score:"..game.Score`

    Using an attribute to get that space for a cleaner look:

    `game.ScoreText = "Score: "`

    `game.ScoreText..game.Score`

    another example (having strings with spaces in two attribute strings, Congrat1 and Congrat2)

    `game.Congrat1 = "You finished in "`
    `game.Congrat2 = " second(s)."`

    `Congrat1..game.MyTime..Congrat2`
  • rebumprebump Member Posts: 1,058
    Of course, if you need just one space between two items, say the text string "Score:" and then the actual score, you can have one actor just display the text "Score:" and then another actor display the actual score value positioned/moved over slightly to create the spacing between it and the "Score:" string from the first actor.
  • spacechimpspacechimp Member Posts: 9
    That .. notation worked great for appending the strings. Thanks! This was very helpful. BTW I didn't see that in the online support docs, I must have missed it?
  • spacechimpspacechimp Member Posts: 9
    Oh, one other strange thing. I have packed some comma delimited data into a string and I want to compare to see if those elements are in the string using the "contains" option in the "whenever" logic"
    Example:
    game.TestAttribute="0,1,2,3,4,5,6,7,8,9"

    whenever game.TestAttribute contains ",2,"

    this should test true, but for some reason this compare does not work! any thoughts?
  • rebumprebump Member Posts: 1,058
    I haven't used the "contains" feature so I unfortunately cannot help at this time. When I get home later today, I'll see what I can discern.

    Just throwing this out there until I can get home:

    For your value that you are trying to see if it is contained...are you, in the text box for the value, entering:

    `",2,"` (with quotes)

    or:

    `,2,` (without quotes)

    If you are using quotes, you may need to remove them. And if you do, not sure if it will complain about the commas...hopefully not...but if so, you could try some other character for delimiting the numbers (i.e. m1m2m3m4m5m).
  • spacechimpspacechimp Member Posts: 9
    The latter without quotes

    ,2,

    but I did try it with quotes as well, neither way seems to work.
  • SlowboySlowboy Member, PRO Posts: 329
    Thanks for the info Rebump, and thanks Spacechimp for asking!
    I didn't know this was possible, and it's helped me tidy my final score screen up a lot!
    Cheers ;]
  • spacechimpspacechimp Member Posts: 9
    Thanks Slowboy and thanks again Rebump. Has anyone been able to get the "contains" working properly? Unless there's some special syntax that I am not aware of, I am stumped! I even tried regular expressions and tried asterisks such as the following example:

    game.TestAttribute="1234"

    whenever game.TestAttribute contains *2*

    Still no luck.
  • rebumprebump Member Posts: 1,058
    Yeah, all the string tests operate like the "is" string test (they only return true, err, match if the whole string matches...guessing something they still need to implement or an obvious bug). No wildcarding or expressions I came up with could match it. Messy around with quotes and backticks didn't help either (it was worth a try).
  • rebumprebump Member Posts: 1,058
    Official post on the string compare operator bug (for folks reference):

    http://gamesalad.com/forums/topic.php?id=2917

    Thanks spacechimp.
Sign In or Register to comment.