How do I detect the type of a parameter

0 favourites
  • 3 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I have a function that receive 2 parameters: a number and a string.

    Because I'm dumb when I code (happens to everybody!), I sometime send the parameter inverted: the number instead of the string and the string in place of the number.

    I want to make this function stupid proof by checking if the parameter received are indeed of the right type. Something like:

    If type of function.param(0) == "number"
    --> browser.log("Incorrect parameter")
    
    If type of function.param(1) == "text"
    --> browser.log("incorrect parameter")[/code:3akx0gtu]
    
    How can I do that? How can I check the type of a variable?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • One solution could be to write a function that would check, character by character, if they are all digits or all letters. But I'm trying to know if there's already a function built it. Something like function isNumber() or isNaN(). Is there anything like that?

  • Oh my god! I'm so blind!!

    It was right there all along! In the list of System conditions!

    For the reference, here's where it is:

    Add condition > System > Is value type

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