- Home /

# Null error trying to create my own number system. How the heck do I fix?

So I have been getting null results and null reference errors from t$$anonymous$$s script

`Null reference: object reference not set to an instance of an object`

I have tried trouble shooting t$$anonymous$$s, but basically I am trying to create a system that allows me to display a huge number to players, w$$anonymous$$le being able to make a code that can run it that goes larger than doubles, but is probably a bit messier... point is, how the heck do I put my number system script and class to use?

```
public class Number_System : MonoBehaviour
{
public static Number_System instance;
public double exponent;
public double mantissa;
// instantiaziation, and enabling use
private void Awake()
{
instance = t$$anonymous$$s;
}
// the maths of the number systems, currently supports addition, subrtaction, multiplication and division, but not any $$anonymous$$gher powers, and division
public void Number_subtraction(Number_System x, Number_System y)
{
if ((y.exponent- x.exponent) > - 4)
{
x.mantissa -= y.mantissa *System.Math.Pow(10, y.exponent - x.exponent);
}
}
public void Number_addition(Number_System x, Number_System y)
{
if ((y.exponent - x.exponent) > -4)
{
x.mantissa += y.mantissa * System.Math.Pow(10, y.exponent - x.exponent);
}
}
public void Number_multiplication(Number_System x, Number_System y)
{
x.exponent += y.exponent;
x.mantissa *= y.mantissa;
}
public void Number_division(Number_System x, Number_System y)
{
x.exponent -= y.exponent;
x.mantissa /= y.mantissa;
}
public void Update()
{
if (mantissa >= 10)
{
mantissa= mantissa/10;
exponent = +1;
}
if (mantissa < 1 && mantissa > 0 )
{
mantissa = mantissa*10;
exponent = -1;
}
if (mantissa < 0 && exponent >= 0)
{
mantissa = mantissa / -1;
}
}
}
```

```
public class Data_system
{
public Number_System color;
public Data_system()
{
color.mantissa = 0;
color.exponent = 0;
}
}
```

```
public class Base_game : MonoBehaviour
{
public Data_system data;
// t$$anonymous$$s code is setting up the instance to be analyzed by other scripts
public static Base_game instance;
private void Awake()
{
instance = t$$anonymous$$s;
}
}
```

```
public class Text_System : MonoBehaviour
{
public Data_system data;
public string color;
void Update()
{
data = Base_game.instance.data;
Debug.Log(data);
}
}
```

What line or lines is the nullref? Makes it much easier to answer.

**Answer** by andrew-lukasik
·
Aug 22, 2022 at 09:26 AM

T$$anonymous$$s code looks unnecessarily complicated. Also - `Number_System`

shouldn't be a `class`

let alone `MonoBehaviour`

(!) because a `struct`

is for values and numbers are values in a very fundamental sense.

What comes to the error itself - it happens in `Data_system`

s constructor as `Number_System color`

field is `null`

:

```
public class Data_system
{
public Number_System color;// t$$anonymous$$s is null
public Data_system()
{
color.mantissa = 0;// color is null but your are trying to access it thus error
color.exponent = 0;// same
}
}
```

If you want my advice:

delete

`Number_System`

delete

`Data_system`

delete

`Base_game`

delete

`Text_System`

complicated code means deadly low productivity -

**keep it simple**, solve real problems; not imaginary onesuse my

**BFN**struct and modify it to suits your needswrite t$$anonymous$$s code again, but in a way that solves somet$$anonymous$$ng, not just to produces complexity (i.e.: problems for the next day)

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.