I'm displaying an integer that changes when I do something, but the int doesn't update when it changes.
In EntityPlayer I have this, which is what I'm displaying
public int miningExp = 0;
public int miningTotal = 0;
public int miningLevel = 1;
(I can't change them to static)
When the level goes up from 1 to 2, it stays at 1, but I know it goes up because I have a chat message pop up saying I leveled up.
Also, skillLevel, skillTotal, and skillExpTo are the three ints I have posted above.
I've tried looking at GuiInGame, and I found the code for experienceLevel, but that didn't work.
I think GuiInGame has a code in it somewhere that makes it always updating, but I couldn't figure out what it was. Can anyone help so it'll update?
The Meaning of Life, the Universe, and Everything.
Join Date:
1/18/2011
Posts:
256
Minecraft:
Plecks
Member Details
Is it only the skill level that doesn't update? If so, you may not be actually incrementing the level once you have enough exp.
Otherwise, where are you running the display code? It needs to be somewhere that gets run constantly (like the display code in GuiIngame does), for example in onTickInGame from ModLoader or the ClientTickHandler in Forge.
You should post more of the code on what's going on with your level up mechanic. If a variable is correctly changed and called there's just no way you should be getting an old value of it.
The only other problem I can think of is the gui might possibly be holding onto an instance of the player that isn't being updated. If that's happening reset the gui entirely on a level up I guess.
You should post more of the code on what's going on with your level up mechanic.
I'll condense the code as much as possible, but have enough to where you can get the point.
EntityPlayer
public void onLivingUpdate()
{
if(alchemyLevel * 50 <= alchemyExp)
{
levelUp(1);
addChatMessage("Your Alchemy Level has increased to " + alchemyLevel);
alchemyExp = 0;
}
}
public void levelUp(int skillLeveling)
{
if(skillLeveling == 1)
{
++this.alchemyLevel;
}
}
public void addSkillExperience(int skillGaining, int expGain)
{
this.skillRaising = skillGaining;
this.expGained = expGain;
if(this.skillRaising == 1)
{
this.alchemyTotal += this.expGained;
this.alchemyExp += this.expGained;
}
}
//Basically what happens, is addSkillExperience() is called.
//addSkillExperience(1, 50) will give skill 1 (alchemy) 50 exp.
//when it levels up, it calls levelUp() making the level increase.
PRGuiSkills
public void drawScreen(int i, int j, float f)
{
drawString(fontRenderer, (new StringBuilder()).append("").append(skillName + " Level").toString(), width / 2, height - 93, 0xffffff);
drawString(fontRenderer, (new StringBuilder()).append("").append("Skill Level: " + skillLevel).toString(), width / 2, height - 77, 0xffffff);
drawString(fontRenderer, (new StringBuilder()).append("").append("Total Exp: " + skillTotal).toString(), width / 2, height - 45, 0xffffff);
drawString(fontRenderer, (new StringBuilder()).append("").append("Exp to: " + skillExpTo).toString(), width / 2, height - 13, 0xffffff);
}
//When the alchemy button is clicked, it'll set skillName to "Alchemy, skillLevel to a method to get the alchemy level, same with skillTotal and skillExpTo.
In EntityPlayer I have this, which is what I'm displaying
public int miningExp = 0;
public int miningTotal = 0;
public int miningLevel = 1;
(I can't change them to static)
and one display code I've used is this:
When the level goes up from 1 to 2, it stays at 1, but I know it goes up because I have a chat message pop up saying I leveled up.
Also, skillLevel, skillTotal, and skillExpTo are the three ints I have posted above.
I've tried looking at GuiInGame, and I found the code for experienceLevel, but that didn't work.
I think GuiInGame has a code in it somewhere that makes it always updating, but I couldn't figure out what it was. Can anyone help so it'll update?
Otherwise, where are you running the display code? It needs to be somewhere that gets run constantly (like the display code in GuiIngame does), for example in onTickInGame from ModLoader or the ClientTickHandler in Forge.
The skills are the thing that aren't updating.
The display code is in drawScreen() of my GUI.
Do you know one that's run constantly in GUIs?
You don't happen to know how to use onTickInGUI, do you?
The only other problem I can think of is the gui might possibly be holding onto an instance of the player that isn't being updated. If that's happening reset the gui entirely on a level up I guess.
I'll condense the code as much as possible, but have enough to where you can get the point.
EntityPlayer
PRGuiSkills