string - Whats wrong with my javascript Object? -


i have javascript "object." im using word object make things easier. here:

var character = {     name: "",     myclass: "",     health: 20,     maxhealth: 20, }; 

say have game, , game has fights, , after each fight gain health point. done with:

character.maxhealth += 1; 

however... when tried this, ended getting 201 maxhealth or 2032 or 203232 or whatever number wanted add max health adding if string. through eyes in looks integer me must mistaken. if can give me hand appreciated. example of have. actual code is:

var character = { name: "", myclass: "", health: 20, maxhealth: 20, stamina: 10, maxstamina: 10, mana: 5, maxmana: 5, physstrength: 3, minattack: 0, mentstrength: 3, physdefense: 3, mentdefense: 3, exp: 0, punch: function() {   toggleattackbuttons(0);   this.minattack = this.physstrength/3;   var damage = math.floor(math.random() * this.physstrength) + this.minattack;   addstring("you punched , did " + damage + " damage.");   myenemy.health -= damage;   updatestats();   settimeout(function(){       myenemy.attack();       toggleattackbuttons(1);       updatestats();       }, 1000); }, kick: function(){   toggleattackbuttons(0);   this.minattack = this.physstrength/3;   var damage = math.floor(math.random() * this.physstrength) + this.minattack;   addstring("you kicked , did " + damage + " damage.");   myenemy.health -= damage   updatestats();   settimeout(function(){       myenemy.attack();       toggleattackbuttons(1);       updatestats();       }, 1000); }, }; 

and im incrementing number:

var updatestats = function() {   document.getelementbyid("charhealth").innerhtml = "health: " + character.health + " / " + character.maxhealth;   document.getelementbyid("enemhealth").innerhtml = "health: " + myenemy.health + " / " + myenemy.maxhealth;   if(myenemy.health <= 0){     myenemy.health = 0;     character.maxhealth += 1;     removefightscreen(1);   }   if(character.health <= 0){     removefightscreen(2);   } }; 

i understand object messy plan on rewriting in future lot more efficient. im roughing right now.

i found myself answer. im sorry lack of code evidence, contains cookies, when write cookies using character stats health , maxhealth, end being converted strings fit cookie. therefore need convert them integers. thank guys help. next time add in code felt being there several hundred lines of code didnt want go through all.


Comments