read bold only for shorter description
Im programming an inventory, ive set it(i think) to work by pressing arrow keys. Pressing Up Arrow or Down Arrow navigate between arrays. “skillbag”, “magicbag”, and “itembag”, but for some reason excluding the itembag. It never “selects” itembag as the var activeCursor(thats what i use as my variable that is the selected array). Im assuming my If statements under the comment “SET THE ACTIVE CURSOR” are correct… but they arent returning as i thought they would, any idea why?
var itembagCursor : int = 0;
var itembagCursorMax : int = 0;
var skillbagCursor : int = 0;
var skillbagCursorMax : int = 0;
var magicbagCursor : int = 0;
var magicbagCursorMax : int = 0;
var selectedSkill : String;
var selectedMagic : String;
var selectedItem : String;
private var activeCursor : String = "skillbag";
function Start(){
Master.itembag.AddRange(Array("Potion","Ether","Antidote")); //add item to inventory
itembagCursorMax = itembagCursorMax + 2;
Master.skillbag.AddRange(Array("Cross Cut","Dolphin Kick","X-Cut","Slam")); //add multiple items
skillbagCursorMax = skillbagCursorMax + 3;
Master.magicbag.AddRange(Array("Fire","Blizzard","Thunder","Aero"));
magicbagCursorMax = magicbagCursorMax + 3;
//Master.inventory.Sort(); //sort inventory
//Master.skillbag.Remove("slam"); //remove first instance of item
}
function Update(){
selectedItem = Master.itembag[itembagCursor];
selectedMagic = Master.magicbag[magicbagCursor];
selectedSkill = Master.skillbag[skillbagCursor];
/* SET THE ACTIVE CURSOR */
if(activeCursor == "skillbag" && Input.GetKeyDown(KeyCode.UpArrow)){
activeCursor = "itembag";
}
if(activeCursor == "skillbag" && Input.GetKeyDown(KeyCode.DownArrow)){
activeCursor = "magicbag";
}
if(activeCursor == "magicbag" && Input.GetKeyDown(KeyCode.UpArrow)){
activeCursor = "skillbag";
}
if(activeCursor == "magicbag" && Input.GetKeyDown(KeyCode.DownArrow)){
activeCursor = "itembag";
}
if(activeCursor == "itembag" && Input.GetKeyDown(KeyCode.UpArrow)){
activeCursor = "magicbag";
}
if(activeCursor == "itembag" && Input.GetKeyDown(KeyCode.DownArrow)){
activeCursor = "skillbag";
}
/* ENABLE ACTIVE CURSOR TO NAVIGATE ITEMS <- & -> */
if(Input.GetKeyDown(KeyCode.LeftArrow) && activeCursor == "itembag"){
itembagCursor = itembagCursor - 1;
}
if(Input.GetKeyDown(KeyCode.RightArrow) && activeCursor == "itembag"){
itembagCursor = itembagCursor + 1;
}
if(Input.GetKeyDown(KeyCode.LeftArrow) && activeCursor == "magicbag"){
magicbagCursor = magicbagCursor - 1;
}
if(Input.GetKeyDown(KeyCode.RightArrow) && activeCursor == "magicbag"){
magicbagCursor = magicbagCursor + 1;
}
if(Input.GetKeyDown(KeyCode.LeftArrow) && activeCursor == "skillbag"){
skillbagCursor = skillbagCursor - 1;
}
if(Input.GetKeyDown(KeyCode.RightArrow) && activeCursor == "skillbag"){
skillbagCursor = skillbagCursor + 1;
}
/* DONT ALLOW THE CURSOR TO NOT BE ON AN ITEM IN THE ARRAY AKA BLANK(NULL) */
if(itembagCursor > itembagCursorMax){
itembagCursor = 0;
}
if(itembagCursor < 0){
itembagCursor = itembagCursorMax;
}
if(skillbagCursor > skillbagCursorMax){
skillbagCursor = 0;
}
if(skillbagCursor < 0){
skillbagCursor = skillbagCursorMax;
}
if(magicbagCursor > magicbagCursorMax){
magicbagCursor = 0;
}
if(magicbagCursor < 0){
magicbagCursor = magicbagCursorMax;
}
}
function OnGUI(){
GUI.Label(Rect(0,Screen.height - 60,30,20), selectedSkill);
GUI.Label(Rect(0,Screen.height - 40,30,20), selectedMagic);
GUI.Label(Rect(0,Screen.height - 20,30,20), selectedItem);
}