PDA

View Full Version : Variable Help, Life System!?


gav.cooper
11-09-2007, 10:40 PM
Hello,

I’m trying to add a life system into a game I’m working on…

Thus far I have this Var setup on the main timeline…

var numLife:Number = 3;
txtLife.text = numLife

then inside an MC (each MC holds a seperate level) i have this code attached to a button...

on (release) {
if (_root.numLife <1)
gotoAndPlay ("gameover");
}else{
_root.numLife = _root.numLife - 1
_root.txtLife.text=_root.numLife
}

then i'm getting this error...

**Error** Symbol=Lv 01 STAGE 01 MC, layer=wave sy, frame=14:Line 4: 'else' encountered without matching 'if'
}else{

Total ActionScript Errors: 1 Reported Errors: 1

_root.numLife = _root.numLife - 1
_root.txtLife.text=_root.numLife}

basically i want it so that when the player clicks the button it takes off 1 life, after 3 clicks it then goes to the "gameover" screen...

can anyone help fix my code? :confused:

gav.cooper
11-10-2007, 12:04 AM
*update... but still needing help

got it working kind of... but the life counter jumps from 3 to 0 with one click on the button, instead of counting down 3,2,1 with each click...

on (release) {
if (_root.numLife = 0) {
_root.gotoAndPlay("gameover");
} else {
_root.lives=_root.lives - 1;
_root.txtLife.text=_root.numLife;
}
}


??? :eek:

gav.cooper
11-10-2007, 12:43 AM
problem solved... :)

just in-case anyone runs into a similar prob...

on (release) {
_root.numLife = _root.numLife - 1;
_root.txtLife.text=_root.numLife;
if (_root.numLife <= 0) {
_root.gotoAndPlay("gameover");
}
}

(cheers Chris)