Search code examples
construct-2

How do I add a variable to a piece of text?


I am creating a side scroller game, and I want a counter on the UI that counts how many times the player has died. But, I do not know what to add to what I have already. I tried typing the variable name behind the &, but it did not accept that. What do I do to put a variable in a set of text?

enter image description here

I am using the free version.


Solution

  • The & is the string concatenation operator in Construct 2.

    For global variables:

    "Deaths: " & VARIABLE_NAME
    

    For instance variables:

    "Deaths: " & instanceName.variableName
    

    Note the " around the string.

    NB: There is no need to explicitly convert the number to a string, it will be done implicitly.