,loop through a hashtable

Hello

I need to put the entries of a hashtable into an array so I can pick one at random.

Here is the idea:
-instntiate an array that is as long as the hashtable has elements
-loop though all of the hashtable’s elements and put them each into one slot of the array
-pick a random number between 0 and the array’s length
-shoose the onject inside that slot

My hashtable stores player characters (Gameobject) as values and their unique player number (int) as keys.
Here is my code:

	var currentPrey: GameObject;
	var preyOptions: Hashtable = new Hashtable();
	
	function StartPursuit(){
		var i: int = 0;		
		//pick a random player (WORK IN PROGRESS)
		var playerIndices: int[] = new int[preyOptions.Count];
		for(var myPlayer in preyOptions.Keys){
			i = myPlayer;
			playerIndices _= preyOptions*;*_

* }*

* var newPreyIndex: int = Random.Range(0, preyOptions.Count);*

* currentPrey = preyOptions[newPreyIndex] as GameObject;*
* }*
The idea is to have a piranha chase a player in range. In multiplayer when the target escapes the piranha should pick one of the other players in range. So the piranha keeps track of all players in a hashtable.
Problem:
preyOptions.Keys is of type Object, but I need an int (all keys in this hashtable are int). Is there a way to tell the hashtable that all of its entries are int-Gameobject pairs? I wouldn’t mind if anyone can point me to a better alternative than hashtables (I use javaScript)

Maybe you’re not being explicit enough when you create the entries in your hash.

The following works fine for me, so it is possible to use ints as keys:

class FunkyClass
{
	var name  :  String;
	var game  :  String;

	function FunkyClass ( theName, theGame )
	{
		name  =  theName;
		game  =  theGame;
	}

	function toString ()
	{
		return "My name is " + name + " and my game is " + game;
	}
}

function doStuff ()
{
	var nameList  =  new Array("Stu", "Karl", "Lenny", "Clyde");
	var gameList  =  new Array("Disco", "Funk", "Boogie", "Jazz");

	var funkHash  =  new Hashtable();

	for ( var i : int = 0; i < 4; i ++ ) {
		var freshFunk : FunkyClass = new FunkyClass(nameList_, gameList*);*_

_ funkHash = freshFunk;
* }*_

* for ( var theKey : int in funkHash.Keys ) {*
* var theFunk : FunkyClass = funkHash[theKey];*
* print(theFunk.toString());*
* }*
}

I’m not sure I understand why do you need the hashtable?
Why not just have an array of GameObjects and random the index?
e.g:

private var prey : GameObject[];

function StartPursuit()
{
   var newPreyIndex: int = Random.Range(0, prey.Length);
   currentPrey = prey[newPreyIndex];
}