Variable types, string vs number
Is there any way that I can check the native type of an object script variable? (similar to the typeof check in javascript)
I see that the DynamicArray class uses the type of the variable for its output, I would like to do something similar when I receive a value as an argument to my method.
USER>s var1 = 123 //No quotes, number type
USER>s var2 = "123" //quotes, string type
//DynamicArray can tell the difference
USER>s arr = []
USER>d arr.%Push(var1)
USER>d arr.%Push(var2)
USER>w arr.%ToJSON()
[123,"123"] //first value is output without quotes, second value is quoted
Yes, no problem:
One way to do this is comparing $listbuilds of the variable in question. Note also that you can coerce any value to a number with the "+" operator. So, for example:
There's not really a simple built-in function to do exactly what you want though (at least that I know of).
You can do something like this. It may not be perfect for your situation but it works.
set value = 1
If value'?.N{
// if it's not a number do something here
}
if value?.N{
//if it's a number do something else here.
}