Array - Convert Object into Int

I seem to be really struggling here? I cant find a solution on google… unless I’m missing something?

I have an Object Array called playerKills, and I want to add 1 as an int to it (the array only holds Ints):

var playerKills = new Array();

//Expression 'self.playerKills.get_Item(i) cannot be assigned to
playerKills[0] ++;

//Just keeps adding '1' to the end of the value
playerKills[0] = "" + 1;

//Ambiguous reference 'parseInt' .....
var arrayValue = parseInt(playerKills*);*

var newValue = arrayValue + 1;
playerKills = “” + newValue;
What am I doing wrong here?
Ollie

var kills : int = playerKills[0];
playerKills[0] = kills + 1;

Never use Array. You can use ++ with a built-in array of ints, but not List; in that case just add 1 the usual way.

import System.Collections.Generic;

function Start () {
	var foo = new int[1];
	foo[0]++;
	
	var foo2 = new List.<int>();
	foo2.Add(0);
	foo2[0] = foo2[0] + 1;
}

Try:

var playerKills = new Array();

//Expression 'self.playerKills.get_Item(i) cannot be assigned to
playerKills[0] ++;

//Just keeps adding '1' to the end of the value
playerKills[0] = playerKills[0] + 1;// I changed "" to playerKills[0] This adds 1 to the old value

//Ambiguous reference 'parseInt' .....
var arrayValue = parseInt(playerKills*);*

var newValue = arrayValue + 1;
playerKills = playerKills + newValue; //I changed “” to playerKills This adds newValue to the old value
I don’t know if i really got your problem. That was just what i found a bit weird in your script.

Why don’t you just do this?

`
var playerKills:Array = new Array();

function AddPlayer():void
{
playerKills.Push(0); //make an instance of the int
}

function AddKill(playernum:int):void
{
playerKills[playernum] = parseInt(playerKills[playernum].ToString())+1; //add 1
}
`

Or alternatively use a built-in.

`
var playerKills:int = new int[0];

function AddPlayer():void
{
var temp:int = new int[playerKills.length+1];
for(var i:int=0; i

Built-ins are faster but it depends on how many players you are adding in those code examples.
`

This is .NET, so you can use System.Convert.ToInt32 instead of parseInt:

playerKills[0] = System.Convert.ToInt32(playerKills[0]) + 1;

This way you can get rid of implicit downcast warnings.