PDA

View Full Version : Skillbook Help


Ultimatepuff
12-08-2007, 01:42 AM
Well in my game, each time you level up a skillbook pops up, allowing you to increase various skills.

I made it so that if the exp was equal to or greater than 15, then the level would become 2 and the skill points would +=3. Thing is, if I do that, then the skill points just keep on increasing by 3 without end, and if I try a =3 instead of +=3 then it always stays at 3! This is with Actionscript 2.0 by the way, help?

neilmmm
12-08-2007, 09:02 PM
i don't really understand your question

but i think you need an extra var to control your levelPoints

does this help?

var score:Number=0;
var level:Number=0;
var levelPoints:Number=0;
onMouseDown=function () {
score+=3;
levelPoints+=3;
if (levelPoints>=15) {
level++;
levelPoints-=15;
}

trace("score = "+score+ " level "+level+" levelPoints "+levelPoints);
trace("");
}

Sephur
12-09-2007, 05:41 AM
Well, I'd have to say that the way Neil posted it makes sense, with a few exceptions.
He put "score" in the onMouseDown, when he should have put "skillpoints" or "sp" or whatever variable you used in the if statement found WITHIN the onMouseDown.
Second. I'm guess the if statement Ultimatepuff is using is in an "onClipEvent(enterFrame)" instead of "onMouseDown()" event handler, which is why it would constantly keep adding 3, or persisting that the skill points are at 3.

My guess, like Neil's, is that as soon as levelpoints hits 15, you just forgot to set it less than 15 again. That would make sense, seeing as if it's += 3;, you're adding 3 every frame or if it's = 3, it's setting skill points to 3 EVERY frame. I've done stuff like that my fair share of times. So, I'll leave out all the examples I have.

If you get nothing else out of this post, remember to keep your eye on your if statements and their contents as if they were out to assassinate you... well, maybe I could have used a better analogy.

Anywho, if you use a variable in the condition and the condition's messing up, make sure that if you're editing that variable somewhere, you're not making it contradict the condition.

rrh
12-09-2007, 06:38 PM
Though the usual way experience is handled, your experience doesn't reset every time you level up.

Usually what it does is when you pass 15, you level up, then you level up again when you pass 30, 45, 60, etc.

So then what you'd do is test
if (exp>=15*level) {
level++;
skillPoints+=3;
}

Sephur
12-09-2007, 09:16 PM
That's really not that important. I've seen plenty of games where they just keep a running tabulation of how much exp you have for the current level. There are plenty of recursive formulas (level * 15 + levelpoints) to find your total experience, and if we're talking about RPG conventions, very few actually increase the necessary experience in a linear manner. Unless you meant to say:


if(levelpoints>level*15){
level++;
levelpoints-=15;
}