How to detect if a string is a string of a number?

Get help using Construct 2

Post » Thu Nov 26, 2015 8:04 pm

Sup guys.

This is an interesting little problem that I've somehow never ran into before. I feel like I may be missing something obvious.

I think this image conveys my problem clearer:

Image

One thing that I thought would work was to use int(), thinking that int("10") would give 10 but int("string") would give me NaN.. but int("string") actually returns the integer 0. So this can't be used as it would turn "Apple" into 0 and then claim it's a number.

Thanks for help

edit: solved it, I was missing something obvious, I just have to use the "is NaN" condition.
Last edited by keepee on Thu Nov 26, 2015 8:44 pm, edited 1 time in total.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Nov 26, 2015 8:18 pm

first thought:
fn.Param(0)=int(fn.Param(0)).........."Number"
else......................................................."String"
Image
B
61
S
23
G
7
Posts: 1,461
Reputation: 10,686

Post » Thu Nov 26, 2015 8:33 pm

@korbaach Naw, the string "10" does not equal to the number 10.. that's a good idea though I thought it would fix it for a moment.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Nov 26, 2015 8:42 pm

Solved it.. I just have to use "is NaN"

silly me
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: fisholith, RetroSpock and 13 guests