LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Methods of determining variable type

Root / Programming Questions / [.]

snail_Created:
Something that SB lacks and would be rather helpful is some kind of typeof statement. Of course, we can make our own functions so I thought I would ask: are there any known methods of type detection? Only needing to check between number and string is fine for now, but checking for int/real and even array/value would be useful for the future.

The type of every built-in function is defined in the SmileBasic documentation. The type of every variable, parameter, and OUT-type value is determined by the suffix (or lack thereof) on the identifier. Where is there a need for 'typeof'?

Variable type is not checked strictly when passing a value to a function, so this could result in undefined behavior or errors when writing a DEF block that might handle any type of variable. Being able to detect variable type would allow the developer to handle these cases.

Whoa, you're right. PRINT TEST1(2) PRINT TEST1("2") END DEF TEST1 (VAR1) RETURN VAR1*2 END shows 4 22 Wild!

You can't thank me for that one, bluesun and calc figured that out in chat the day before it even came out.

A post made 2 days ago by calc84maniac is very helpful: http://smilebasicsource.com/page?pid=51