How do I detect the type of a parameter

Just started using Construct 2? Post your questions here

Post » Tue Aug 04, 2015 3:10 am

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:

Code: Select all
If type of function.param(0) == "number"
--> browser.log("Incorrect parameter")

If type of function.param(1) == "text"
--> browser.log("incorrect parameter")


How can I do that? How can I check the type of a variable?
B
20
S
5
Posts: 80
Reputation: 1,408

Post » Tue Aug 04, 2015 3:16 am

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?
B
20
S
5
Posts: 80
Reputation: 1,408

Post » Tue Aug 04, 2015 4:14 am

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
B
20
S
5
Posts: 80
Reputation: 1,408


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest