I've noticed a couple errors going around that I'd like to help clarify for people.
The first one is people using y=y+variable, or variable=variable+1;
Please stop doing this. You are telling the computer that variable=variable? The computer already knew that. Variable=variable before you even typed anything. Anything always equals itself.
The correct way is variable+=1; You can use any math function in that. Variable*=.95; Even variable/=.95; or y*=-.5;
Everything you tell the computer to do takes a bit of cpu to perform; That's why we tell you to stay away from if if you can. that's why we tell you to use timers or other events instead of draw actor. Draw actor checks every frame. Imagine that...telling the computer that y=y 30 times a second. It eats up cpu fast, yet accomplishes nothing.
The second is using textNumber as a variable. This is bad for many reasons, one being that if you want to change it for a certain purpose, and yet display it at the same time, the display becomes meaningless. What's more, you can't use it to make advanced functions, which you will be using if you are ever making a full, commercial quality game. You also can't save textNumber. Its like trying to build a house out of paint.
Another is people using 'if' when its not necessary. One thing i see are people using multiple ifs to make a mickey-moused case switch.
if (powerlevel==1){do this};
if (powerlevel==2){do this};
The correct way is
switch(powerlevel){
case 0:
do this;
break;
case 1:
do this;
break;}
When using if's like that, the computer will check every single if to see if any are correct; but with a case switch, it begins the switch already knowing the variable; once a case is true, it ignores the rest of the cases.
And also using if to make a mathematical adjustment is silly.
if (canjump==1){yvelocity-=8;canjump=0;}
The correct way here is
yvelocity-=8*canjump;
canjump=0;
Actions are applied to the frame they are triggered in; in the above example, yvelocity will perform its function with the current canjump, it will be applied to the frame, and the player will move upward, THEN canjump will become 0.
Lastly, don't create more actors or more variables when you don't need to. Use cloneindex and integer arrays.
A prime example is with text actors displaying variables; don't make a separate text actor for health, gold, etc.
Instead, clone the actor, and use a case switch:
switch(cloneindex){
case 0:
textNumber=player.hp;
break;
case 1:
textNumber=player.gold;
break;
case 2:
textNumber=player.time;
break;
}
Now all your display variables are in one action. You don't have to go chasing around to find what's what.
I hope this helps someone.