- Home /
Problems with 2d arrays , += incrementing values
Hi guys, i dont understand why i cant += the tempEssence and referenceAmount variable together when they are both floats. My intention is for when E is up after being pressed down, i want to add a value to a multidimesional array of size, (a x 2) a >= 1; I have initialised variables as shown. I dont know why but rather then adding to tthe location in the array it just overwrites it.
var tempReference = new Array(selectedEntity,tempEssence);
var tempEssence:float = 0f;
var lifeEssenceCarrier:float = 0f;
var entityWithinReach:boolean = false;
var extractEssenceSpeed:float = 10f;
var selectedEntity:String = "default";
var selectedEntityObject:GameObject;
var maxHealth:float = 100;
var minHealth:float = 0;
var objectReference = new Array();
In the update method i have:
f(Input.GetKeyUp(KeyCode.Q) || Input.GetKeyUp(KeyCode.E)) {
var foundEntityInArray = false;
tempReference[0]= selectedEntity;
tempReference[1]= tempEssence;
if(objectReference.length == 0) {
objectReference.Push(tempReference);
}
for(i = 0; i < objectReference.length; i++) {
for(j = 0; j < tempReference.length; j++) {
if(selectedEntity == objectReference[i][j]) {
var referenceAmount:float = objectReference[i][1];
objectReference[i][1] = tempEssence + referenceAmount;
foundEntityInArray = true;
}
}
}
if(!foundEntityInArray) {
objectReference.Push(tempReference);
}
Debug.Log(objectReference[0][1]);
// Debug.Log(selectedEntity == (objectReference[0][0]));
resetTempEssence();
}
Specifically the middle for loop is the issue where it is not += to objectReference[i][1].
Help would be much appreciated.
Thanks a bunch
Comment
Your answer

Follow this Question
Related Questions
2D array problem in C# 2 Answers
2d array.What is the difference between these two? 1 Answer
What type of Array should I use? 1 Answer
How to cut off an array of gameobjects? 1 Answer
How to remove gaps in a 2D map. 0 Answers