trouble accessing components from handles

Hello, hope all is well =]

I have 7 dice called Dice1 to Dice7. They each have a script attached called Script_Dice.
I can find the 7 gameObjects, store their GameObject and Script Component in an ArrayList, but this is where I get stuck.

I cannot call the functions on any of the gameObjects’ Scripts, read/write to their public vars, or even access the GameObjects’ Components.
I’m sure I have done this before , but am currently going in loops (and slightly loopy).
Could some please explain or pass a reference link to help me understand what handle I can use to access components, and instances/methods on script components? many thanks :S

EDIT :
The actual ArrayList builds fine, as in the Log : Dice1 (UnityEngine.GameObject) , [same for Dice2,3 etc].

The problem is more that I have saved the Dice script in the list already with

diceScripts.Add(GameObject.Find("Dice" + i.ToString()).GetComponent("Script_Dice") as Script_Dice);

and I cannot work out why i am not able to just call a public function on that stored script with

diceScripts[1].RollDice();

i just keep getting is not a member of ‘Object’.

EDIT 2 : upped full scripts , both player and dice.

Most of this script is comments on what i’ve tried and the Debug.Log results . Please note this is a skeleton for what i am planning , not a working full result yet :

Player_Manager script :

//#pragma strict

//import System.Collections.Generics;
// Assets/Player_Manager.js(3,8): BCE0021: Namespace 'System.Collections.Generics' not found, maybe you forgot to add an assembly reference?

public class Player_Manager extends MonoBehaviour
{
	public static var Instance : Player_Manager;
	
	public static var diceObjects = new ArrayList();
	
	public static var diceScripts = new ArrayList();
	//public static var diceScripts = new List.<Script_Dice>(); // Assets/Player_Manager.js(13,45): BCE0005: Unknown identifier: 'List'.
	
	// var myList : List.<Type> = new List.<Type>();  // declaration
	//public static var diceScripts : List.<Script_Dice> = new List.<Script_Dice>(); // Assets/Player_Manager.js(16,41): BCE0018: The name 'List' does not denote a valid type ('not found'). Did you mean 'UnityEngine.Light'?
	
	public static var diceRolling = new ArrayList();
	public static var runners = new ArrayList();
	public static var brains : int = 0;
	public static var shots : int = 0;
	
	public enum PlayerTurnState
	{
		Idle, PickDice, RollDice, ChooseBank, ChooseContinue, BeenShot, CalculateResult
	}
	
	
	function Start() 
	{
		Instance = this;
		
		for (var i : int = 1; i < 8; i ++)
		{
			diceObjects.Add(GameObject.Find("Dice" + i.ToString()).gameObject as GameObject);
			diceScripts.Add(GameObject.Find("Dice" + i.ToString()).GetComponent("Script_Dice") as Script_Dice);
			
			Debug.Log(diceObjects[i-1]);
			// Dice1 (UnityEngine.GameObject) UnityEngine.Debug:Log(Object) Player_Manager:Start() (at Assets/Player_Manager.js:39)

			Debug.Log(diceScripts[i-1]);
			// Dice1 (Script_Dice) UnityEngine.Debug:Log(Object) Player_Manager:Start() (at Assets/Player_Manager.js:42)
			
			// all these say : is not a member of 'Object'. 
			/*
			Debug.Log(diceObjects[i-1].transform.position);
			Debug.Log(diceObjects[i-1].gameObject.transform.position);
			Debug.Log(diceObjects[i-1].parent.gameObject.transform.position);
			
			Debug.Log(diceScripts[i-1].transform.position);
			Debug.Log(diceScripts[i-1].gameObject.transform.position);
			Debug.Log(diceScripts[i-1].parent.gameObject.transform.position);
			*/
			
			//diceAll[i-1].gameObject.renderer.enabled = false;
		}
		
		Reset();
	}
	
	function Update() 
	{
		if (Input.GetKeyUp(KeyCode.J))
		{
			for (var v = 0; v < 7; v ++)
			{
				Debug.Log(diceScripts[v]); // Dice1 (Script_Dice) UnityEngine.Debug:Log(Object) Player_Manager:Update() (at Assets/Player_Manager.js:58)
			//	diceScripts[v].GoNoMaterial();
			//	diceScripts[v].RollDice();
			//	Debug.Log(diceScripts[v].posStart);
			}
			
			for (var dice in diceScripts)
			{			
				Debug.Log(dice); // Dice1 (Script_Dice) UnityEngine.Debug:Log(Object) Player_Manager:Update() (at Assets/Player_Manager.js:66)
				//dice.GoNoMaterial();	
				//Debug.Log(dice.posStart);
			}
		}
	}
	
	function Reset() 
	{
		// make dice grey
		
		// clear arrayLists
		
		// 
	}
}

Script_Dice script :

#pragma strict

public class Script_Dice extends MonoBehaviour
{
	public enum DiceColour
	{
		Red, Yellow, Green
	}
	
	public enum DiceFaceType
	{
		Brain, Shot, Runner
	}
	
	public var isAtRest : boolean = false;
	public var maxForce : int = 10000;
	public var sideFacingUp : int = 0;
	public var myColour : DiceColour;
	public var myFace : DiceFaceType;
	
	private var counter : float = 0.0;
	public var posStart : Vector3; // private , but made public to look at for testing only
	
	function Start()
	{
		renderer.enabled = false;
		posStart = transform.position;
		applyForce();
	}	
	
	function Update() 
	{
		if (rigidbody.velocity.magnitude < 0.005 && !isAtRest)
		{
	    	sideFacingUp = CalcSideUp();
	    	isAtRest = true;
	    	//if (sideFacingUp > 0) Debug.Log("sideFacingUp = " + sideFacingUp);
    	}
    	else if (rigidbody.velocity.magnitude > 0.005)
    	{
    		isAtRest = false;
    		sideFacingUp = 0;
    	}
    		
    	if (isAtRest)
    	{
    		if (sideFacingUp == 0)
    		{
    			applyForce();
    			isAtRest = false;
    		}
    		
    		counter += Time.deltaTime;
    		if (counter > 2.0)
    		{
    			Debug.Log(this.gameObject.name + " has settled");
    			counter = 0.0;
    			
    			//RollDice();
    			
    			GoGreyMaterial();
    		}
    	}
	}
	
	function CalcSideUp() 
	{
    	var dotFwd : float = Vector3.Dot(transform.forward, Vector3.up);
    	if (dotFwd > 0.99f) return 5;
    	if (dotFwd < -0.99f) return 2;

    	var dotRight : float = Vector3.Dot(transform.right, Vector3.up);
    	if (dotRight > 0.99f) return 4;
    	if (dotRight < -0.99f) return 3;

    	var dotUp : float = Vector3.Dot(transform.up, Vector3.up);
    	if (dotUp > 0.99f) return 6;
    	if (dotUp < -0.99f) return 1;

    	return 0;
    }
    
    public function RollDice()
    {
    	transform.position = posStart;
    	applyForce();
    }
	
	function applyForce()
	{
		var rndForceX : int = Random.Range(-maxForce, maxForce);
		var rndForceY : int = Random.Range(-maxForce, maxForce);
		var rndForceZ : int = Random.Range(-maxForce, maxForce);
		rigidbody.AddForce(Vector3(rndForceX, rndForceY, rndForceZ));
		
		var rndTorqueX : int = Random.Range(-maxForce, maxForce) * 1000;
		var rndTorqueY : int = Random.Range(-maxForce, maxForce) * 1000;
		var rndTorqueZ : int = Random.Range(-maxForce, maxForce) * 1000;
		rigidbody.AddTorque(Vector3(rndTorqueX, rndTorqueY, rndTorqueZ));
	}
	
	public function GoGreyMaterial()
	{
		renderer.enabled = true;
	}
	
	public function GoDiceMaterial()
	{
		renderer.enabled = true;
	}
	
	public function GoNoMaterial()
	{
		renderer.enabled = false;
	}
}

you can probably guess by my enum states this is to be a clone of ‘Zombie Dice’ =]

That’s another reason why i never use UnityScript. :wink: Most UnityScript users promote the language because you don’t have to worry about types, but there are so many (unlogical) exceptions which makes it actually even harder to understand what’s going on.

In general, no matter if you use C# or UnityScript, you should avoid using dynamic-typed variables (such as the Array or ArrayList class). Beside that it makes the access slower, you also need to cast it back to the right type (in UnityScript you usually don’t have to do this).

Personally i use only C#, but that doesn’t matter. You can use almost the same things in UnityScript. A generic List will solve your problem (I guess…):

//You need to import the generic namespace at the top:
import System.Collections.Generic;

//[...]
var diceObjects = new List.<Script_Dice>();

//Now use it like an Array.

The documentation of the List class is here, however since it’s part of the .NET framework (and Mono is the open source variant of it), the examples are only available in “real” .NET languages like C#, C++/Cil, F#, VB .NET, …

Sounds like indexing into diceScripts gets you a reference of type Object when you’re expecting Script_Dice.

If you have strict typing enabled, the compiler will complain because you’re calling functions that only exist in the one class and not the other. If you’re using dynamic typing, this should work as long as the list only contains references of the type you expect.

If you want to continue using strict typing, you could typecast your references, or use another data structure that allows you to specify the desired type (haven’t seen it before, but a quick search turned up this article on the Unify community wiki).