Return value 'getScriptVar' when var/script doesn't excist?

Started by TheDutcher, March 19, 2015, 03:49:52 PM

Previous topic - Next topic

TheDutcher

Hey, I was just wondering what the 'getScriptVar' function will return when the unit doesn't have the specified script or the script not the variable (for whatever reason).
As far as I know CRPL doesn't really has any 'null' value, and returning 0 would be rather inaccurate, since then you wouldn't be able to distinguish units not containing a script from a unit where the value of the variable would be actually 0.


warren

Okay, so it returns null. How does this value behave? More importantly, what other ways can it be generated? Can it be tested for? Can it be differentiated from zero?

TheDutcher

Quote from: Karsten75 on March 19, 2015, 03:59:06 PM
Have you tried it? :)
I tend to forget such things...

Tried it out and it appears to return nothing, I'm not sure if that nothingness is an empty string or an actual null value (which I think isn't possible in a stack language?), so that question would remain, shouldn't know how to test that.

knucracker

There actually is a "null" internal type in CRPL.  All data in CRPL is represented internally by a structure that can be Null, Int, Float, List, etc.  This struct can be any of those types and can coerce into any primitive instance type. 

So, Null is returned in the case you are asking about.  If you multiply Null by a number, it will coerce into 0.  If you treat it as a string it will be "".  If as a List it will be an empty list, etc.

TheDutcher

Quote from: virgilw on March 20, 2015, 07:09:32 PM
There actually is a "null" internal type in CRPL.  All data in CRPL is represented internally by a structure that can be Null, Int, Float, List, etc.  This struct can be any of those types and can coerce into any primitive instance type. 

So, Null is returned in the case you are asking about.  If you multiply Null by a number, it will coerce into 0.  If you treat it as a string it will be "".  If as a List it will be an empty list, etc.
So the only way to check whether it returns a null value would be by checking for these 3 values (0, "", empty list)? No actual function to check for null (or well, basically check which type a certain value is)? That's a bummer... And still kinda unsafe way of checking in my opinion.
But thanks nonetheless for the answers, helped out anyway.