Retrieve an integer from an array in a different script

I’m trying to create a script that reads data from a single cell in an array in a different script, and displays the value in an inventory screen. It also changes integers into shortened strings (eg. 5100 to 5.1k). It serves solely as cosmetic.

using UnityEngine;
using System.Collections;

public class GoldCurrent : MonoBehaviour {

	private int GoldStock
	private string GoldFormat

	void Awake () {
		int GoldStock = GameObject.Find("Diety").GetComponent<CurrentStock>().CurrentStockArray[0];
	}
	
	void Update () {
		private string GoldFormat(GoldStock){
			if (GoldStock >= 100000000)
				return (GoldStock / 1000000).ToString("#,0M");

			if (GoldStock >= 10000000)
				return (GoldStock / 1000000).ToString("0.#") + "M";

			if (GoldStock >= 100000)
				return (GoldStock / 1000).ToString("#,0K");

			if (GoldStock >= 10000)
				return (GoldStock / 1000).ToString("0.#") + "K";

        return GoldStock.ToString("#,0");
    } 
}

And a script attached to an object “Diety”,

using UnityEngine;
using System.Collections;

public class CurrentStock : MonoBehaviour {

	public int[] CurrentStockArray = new int[3];
	
	void Start () {
	CurrentStockArray[0] = 12000; //Gold
	CurrentStockArray[1] = 0; //Rations
	CurrentStockArray[2] = 0; //Arrows
	}
}

However, it’s coming up with a few errors…

GoldCurrent.cs(7,15): error CS1519: Unexpected symbol ‘private’ in class, struct, or interface member declaration

GoldCurrent.cs(10,12): error CS1519: Unexpected symbol ‘void’ in class, struct, or interface member declaration

GoldCurrent.cs(16,23): error CS1525: Unexpected symbol ‘private’

I’m fairly new to c#, so if I’ve made some amateur mistake, I’m sorry. What am I doing wrong?

In GoldCurrent the declaration’s of GoldStock and GoldFormat are missing their line ending semi-colons (;).

Also, in GoldCurrent’s Awake function you are trying to retrieve a value from CurrentStock. This won’t work as the values of CurrentStock are initialized in it’s Start function whereas GoldCurrent is getting the values in Awake, which will occur before start.

Try this

    private int GoldStock
         private string GoldFormat
     
         void Star () {
             int GoldStock = GameObject.Find("Diety").GetComponent<CurrentStock>().CurrentStockArray[0];
         }

......rest of class

public class CurrentStock : MonoBehaviour {
 
     public int[] CurrentStockArray = new int[3];
     
     void Awake() {
     CurrentStockArray[0] = 12000; //Gold
     CurrentStockArray[1] = 0; //Rations
     CurrentStockArray[2] = 0; //Arrows
     }
 }