does anyone know a tutorial about writing equations in AS 2. I’m not sure what the format is.
?? what kind of equations …
really simple ones that i should know
its been too long since i’ve tried programming a game
i can’t even remember how to subtract from a variable. i’m trying to set var lifes = 3 and then for every wrong button pressed var lifes gets -1 from it. i was trying to do something like
life -1 -= life
its wrong though
lifes -= 1;
or
lifes--;
or
--lifes;
or
lifes = lifes - 1;
so that first one will subtract 1 from lifes? also if you don’t mind explaining, what is the – do specifically?
so that first one will subtract 1 from lifes?
Yes.
also if you don’t mind explaining, what is the – do specifically?
It subtracts 1 from a number. If you use it before the variable, then the variable evaluates to that value minus 1. If you use it after the variable, the variable evaluates to whatever it was before you tried to subtract one, but its value is one less after it has been evaluated.
var q = 1.4;
trace(q++); // 1.4
trace(q); // 2.4
q = 1.4
trace(++q); // 2.4
trace(q); // 2.4
trace((q++) + ' ' + q); // 2.4 3.4
ah cool! thanks
although it’s probably a good idea to note that --variable subtracts BEFORE the variable is read, and variable-- subtracts AFTER it is read;
var myVariableBefore:Number = 0;
trace(--myVariableBefore); // will thus output -1
var myVariableAfter:Number = 0;
trace(myVariableAfter--); // will thus output 0
EDIT::: SORRY, completely missed the second half of your last post somehow :x