global static function returns nullReference error [unityscript]
hi!
I have a _globals.js:
public static class _globals
{
public static function _map(value, A, B, C, D) : float
{
return (value - A) / (B - A) * (D - C) + C;
}
}
I assign the variables like this in otherScript.js
var b = _globals._map(_brightness, 0, 1, 0, 5);
But it keeps giving my this error:
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) _globals._map (System.Object value, System.Object A, System.Object B, System.Object C, System.Object D) (at Assets/Scripts/_globals.js:11) animations.FixedUpdate () (at Assets/Scripts/animations.js:20)
I'm lost! what am I doing wrong here? From what I understood a static class doesn't need an instance. Alas I tried this as well:
_globals.js:
public class _globals
{
function _map(value, A, B, C, D) : float
{
return (value - A) / (B - A) * (D - C) + C;
}
}
private var g = new _globals();
g._map(blablalbal)
same error! It keeps referring to the _map function but I have no clue what's wrong there. Who can enlighten me?
ps: though I get an error It still gives me the right values and everything works correctly..
Answer by flowen_nl · Feb 01, 2017 at 04:57 PM
alright I sort of fixed the problem... I simply have to turn on the app that sends the OSC, so that the variable actually exists is my guess that fixes this problem o_O
Answer by Landern · Jan 24, 2017 at 02:16 PM
I have zero problem with your static first version once i declared what each parameter to the _map function was, prior to that errors were displaying referencing using the '-' operator on type of Object.
public static class _globals
{
public static function _map(value:float, A:float, B:float, C:float, D:float) : float
{
return (value - A) / (B - A) * (D - C) + C;
}
}
he man! thanks for checking, but I keep getting this error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value)
animations.FixedUpdate () (at Assets/Scripts/animations.js:20)
copy pasted your code...
animations:20 is:
var x = Globals._map(_pos, 0, 1, 0, 15);
and _pos is getting a public value from a different script (using oscReceiver script):
_pos = oscScript.GetComponent.<oscReceiver>()._aa2;
Your answer
Follow this Question
Related Questions
Can the viewport rect of a camera be static? 0 Answers
Unexpected Symbol 'int' 1 Answer
How to get static speed 1 Answer
Highscore not working 0 Answers