Determine if value is text or number?

0 favourites
  • 2 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I'm calling a function with parameters from an external XML file. As such, all values returned are strings. Is there a way to determine if the retrieved value is a string or a number, then convert it accordingly using str() or int()?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct does type casting. If you put a string, which is a number into a number-variable, it will be a number. If it's a string and you try to put it into a number-variable you get a NaN (not a Number). You can test your variable if it's a NaN. So you only have to put the return value in a number-variable an look if it's a NaN. If it's a NaN it is a string otherwise a number.

    Something like only her comes the string from a Textbox:

    Global number myNumber = 0

    + Button: On clicked

    -> System: Set myNumber to TextBox.Text

    + System: myNumber is NaN

    -> Text: Set text to "String"

    + System: Else

    -> Text: Set text to "Number"

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