text object

This forum is currently in read-only mode.
  • how flexible IS the text object?

    i'm trying to setup a hp counter and the action i'm trying to use to achieve this is:

    Text: Set text to RedCastle.Value('HPcurrent') + "/" + RedCastle.Value('HPmax')

    the private variables are initialized to 100 each and with my knowledge of programming, should produce this:


    but i get this instead:


    the period seems to automatically appear

    logical error?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • To remove the period, try setting HPcurrent and HPmax to int(); as for the incorrect result, use & instead of + for concatenation.

    Text: Set text to int(RedCastle.Value('HPcurrent')) & "/" & int(RedCastle.Value('HPmax'))

    Or so I would think.

  • well, whaddaya know! that works! haha

    thanks for the help! <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" />

  • Just to shed some light on what happens here:

    + is arithmetic addition, which means adding numbers, or when used between a string and a string, text concatenation. & always means text concatenation eg. if you use 100 & "%" you get 100%. 100 + "%" won't work because it can't perform arithmetic addition.

    The type checker allows RedCastle.Value('HPcurrent') + "/" because private variables can hold anything so the expression could be valid - it can't tell in the expression editor, it doesn't know the value of 'HPcurrent' yet.

    So it ends up trying to do 100 + "/" at runtime which is invalid, so Construct does nothing (the left operand is unaffected by the addition). Hence 100 + "/" evaluates to 100. Then you add another 100 to it, which gives 200.

    Tip: run a debug, and in this situation a message is added to the log.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)