String concatenation
spacechimp
Member Posts: 9
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!
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
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`
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?
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).
,2,
but I did try it with quotes as well, neither way seems to work.
I didn't know this was possible, and it's helped me tidy my final score screen up a lot!
Cheers ;]
game.TestAttribute="1234"
whenever game.TestAttribute contains *2*
Still no luck.
http://gamesalad.com/forums/topic.php?id=2917
Thanks spacechimp.