java - Trying to debug int arrays -


i'm trying put little game concept in java, , have encountered strange problem; int arrays don't seem storing values in parts of code!
(using netbeans 8.2)
suspect small , tedious have missed.
constructor basic creature. see "addtrait" method? focus.

public creature(string inputname) {     if(debug>0){system.out.println("debug: creature ");}      creaturename = inputname;     size = 1;     population = 1;      addtrait(new trait("test",0,new int[]{4,4,4,4,4,4}),0);     addtrait(new trait("empty",0,new int[]{0,0,0,0,0,0}),1);     addtrait(new trait("empty",0,new int[]{0,0,0,0,0,0}),2);  } 

this method in creature class.

public void addtrait(trait newtrait, int slotnum) {     mytraits[slotnum] = newtrait;      if(debug>0){system.out.println("debug: creature > "             + "addtrait > mytraits["+slotnum+"].getname() = "+             mytraits[slotnum].getname());}           for(int k=0;6>k;k++)         {             system.out.println("debug: creature > "             + "addtrait > mytraits["+slotnum+"].geteffects()["+k+"] = "+             mytraits[slotnum].geteffects()[k]);         }          system.out.println(); } 

in driver class, attempt add "sharp eyesight" trait test creature.

public class evodriver { public static void main(string[] args) {      // initilize traitlist       traitlist mytraits = new traitlist();      // initilize creature      creature player1 = new creature("dragon bear");      player1.addpop();     player1.addpop();     player1.growsize();      // add specific trait      //player1.addtrait(mytraits.gettrait("carnivore"), 0);     player1.addtrait(mytraits.gettrait("sharp eyesight"), 1);     //player1.addtrait(mytraits.gettrait("fire breath"), 2);      //force update     player1.updatestats();     //print creature     player1.printcreature();    } 

this constructor trait.

public trait(string newname, int fv, int[] effects) {     if(debug>0){system.out.println("debug: trait");}      traitname = newname;     feedvalue = fv;      //handle effects     effects[0] = feedertype;     effects[1] = size;     effects[2] = power;     effects[3] = stealth;     effects[4] = senses;     effects[5] = dangerous;      if(debug>0){system.out.println("debug: trait > traitname = "+traitname);}     if(debug>0){system.out.println("debug: trait > senses = "+senses);}  } 

i have class supposed handle initiating stat boosts each trait called traitlist. holds data each trait. however, when method "geteffects" called, result 0!

public class traitlist {  //debug mode  final int debug = 1;    trait[] alltraits = {new trait("empty",0,new int[]{0,0,0,0,0,0})};  // **** constructors ****  /*                              hints ____________________________________________________________________________ effects[0] = feedertype; effects[1] = size; effects[2] = power; effects[3] = stealth; effects[4] = senses; effects[5] = dangerous; */   public traitlist() {      if(debug>0){system.out.println("debug: traitlist ");}        boolean[] special = new boolean[2];     special[0] = false; //alert herd     special[1] = false; //pack tactics      //add effects list      // sharp eyesight; increases senses 3      //feedertype;     //size;     //power;     //stealth;     //senses;     //dangerous;     addtrait(new trait("sharp eyesight", 2, new int[]{0,0,0,0,3,0} )             .setdesc("helps detect other creatures!"));      // camouflage; increases stealth 3      addtrait(new trait("camouflage", 0, new int[]{0,0,0,0,0,0}));      // alert herd; increases senses population number     addtrait(new trait("alert herd", 0, special));      // pack tactics; increases power population number     addtrait(new trait("pack tactics", 0, special));      // carnivore; creature can eat meat; senses +1, stealth +1      addtrait(new trait("carnivore", -1, new int[]{0,0,0,0,0,0}));      // omnivore; creature can eat meat , plants      addtrait(new trait("omnivore", -5, new int[]{0,0,0,0,0,0}));      // horns; increases dangerous 1      addtrait(new trait("horns", 0, new int[]{0,0,0,0,0,0}));       // fire breath; increases dangerous 3, increases power 3; feed 10      addtrait(new trait("fire breath", 10, new int[]{0,0,0,0,0,0})); }  // **** methods ****  public void addtrait(trait newtrait) {     // create temp array     trait[] temp = new trait[1];      temp[0] = newtrait;     trait[] newtemp = new trait[alltraits.length+1];     (int k=0; alltraits.length>k;k++)     {         newtemp[k] = alltraits[k];     }        newtemp[alltraits.length] = temp[0];      alltraits = newtemp;     }  public trait getrandomtrait() // {     return null; }  public int gettraitindex(string searchname)//returns 0 if not found {      for(int k=0;alltraits.length>k;k++)     {         if(debug>0)         {system.out.println("debug: traitlist > gettraitindex > k = "+k);}          if(debug>0)         {system.out.println("debug: traitlist > gettraitindex > "                 + "alltraits[k].getname() = "+alltraits[k].getname());}          if(searchname.equalsignorecase(alltraits[k].getname()))         {             return k;         }     }     system.out.println("error in traitlist > gettraitindex! trait "              + searchname +" not exist!");     return 0; }  public trait gettrait(string name)//returns empty trait if not found {     return alltraits[gettraitindex(name)]; } 

}

i don't know how clear i've been, appreciate hints, advice, hell i'd take useful insult pointing out stupid mistakes. attach debug output.

run: debug: trait debug: trait > traitname = empty debug: trait > senses = 0 debug: traitlist  debug: trait debug: trait > traitname = sharp eyesight debug: trait > senses = 0 debug: trait debug: trait > traitname = camouflage debug: trait > senses = 0 debug: trait debug: trait > traitname = carnivore debug: trait > senses = 0 debug: trait debug: trait > traitname = omnivore debug: trait > senses = 0 debug: trait debug: trait > traitname = horns debug: trait > senses = 0 debug: trait debug: trait > traitname = fire breath debug: trait > senses = 0 debug: creature  debug: trait debug: trait > traitname = test debug: trait > senses = 0 debug: creature > addtrait > mytraits[0].getname() = test debug: creature > addtrait > mytraits[0].geteffects()[0] = 0 debug: creature > addtrait > mytraits[0].geteffects()[1] = 0 debug: creature > addtrait > mytraits[0].geteffects()[2] = 0 debug: creature > addtrait > mytraits[0].geteffects()[3] = 0 debug: creature > addtrait > mytraits[0].geteffects()[4] = 0 debug: creature > addtrait > mytraits[0].geteffects()[5] = 0  debug: trait debug: trait > traitname = empty debug: trait > senses = 0 debug: creature > addtrait > mytraits[1].getname() = empty debug: creature > addtrait > mytraits[1].geteffects()[0] = 0 debug: creature > addtrait > mytraits[1].geteffects()[1] = 0 debug: creature > addtrait > mytraits[1].geteffects()[2] = 0 debug: creature > addtrait > mytraits[1].geteffects()[3] = 0 debug: creature > addtrait > mytraits[1].geteffects()[4] = 0 debug: creature > addtrait > mytraits[1].geteffects()[5] = 0  debug: trait debug: trait > traitname = empty debug: trait > senses = 0 debug: creature > addtrait > mytraits[2].getname() = empty debug: creature > addtrait > mytraits[2].geteffects()[0] = 0 debug: creature > addtrait > mytraits[2].geteffects()[1] = 0 debug: creature > addtrait > mytraits[2].geteffects()[2] = 0 debug: creature > addtrait > mytraits[2].geteffects()[3] = 0 debug: creature > addtrait > mytraits[2].geteffects()[4] = 0 debug: creature > addtrait > mytraits[2].geteffects()[5] = 0  debug: traitlist > gettraitindex > k = 0 debug: traitlist > gettraitindex > alltraits[k].getname() = empty debug: traitlist > gettraitindex > k = 1 debug: traitlist > gettraitindex > alltraits[k].getname() = sharp eyesight debug: creature > addtrait > mytraits[1].getname() = sharp eyesight debug: creature > addtrait > mytraits[1].geteffects()[0] = 0 debug: creature > addtrait > mytraits[1].geteffects()[1] = 0 debug: creature > addtrait > mytraits[1].geteffects()[2] = 0 debug: creature > addtrait > mytraits[1].geteffects()[3] = 0 debug: creature > addtrait > mytraits[1].geteffects()[4] = 0 debug: creature > addtrait > mytraits[1].geteffects()[5] = 0  _________________________________________________ dragon bear (pop: 3) [herbivore] _________________________________________________ size: 2 power: 2 stealth: 0 senses: 0 dangerous: 0 _________________________________________________ trait 1: test  ~ {  } trait 2: sharp eyesight  ~ { helps detect other creatures! } trait 3: empty  ~ {  } _________________________________________________ build successful (total time: 0 seconds) 

if no solution can found, i'll start on scratch. (i'll reuse bits of working code of course!)

in constructor, re-assigning values of effects. potential problem.

effects[0] = feedertype; effects[1] = size; effects[2] = power; effects[3] = stealth; effects[4] = senses; effects[5] = dangerous; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -