PDA

View Full Version : [AS2] flash game lives


ilike2
12-31-2008, 10:39 PM
Basically I’m trying to create something very similar to the link below, but can’t quite figure out how to do the lives part.

http://www.andkon.com/arcade/adventureaction/betterbbqchallenge/

This is the code I have so far:

//resets the thermometer
drink_btn.onRelease = function() {
thermometer_mc.gotoAndPlay("start");
};

//when the thermometer reaches a certain number of frames one live is deducted.
onEnterFrame = function () {
if (thermometer_mc._currentframe == 40) {
lives_mc.gotoAndStop("two_lives");
} else if (thermometer_mc._currentframe == 80) {
lives_mc.gotoAndStop("one_lives");
} else if (thermometer_mc._currentframe == 100) {
lives_mc.gotoAndStop("no_lives");

}
};


I have problems with the lives part. For example if I lose two lives (one life left) then when I click the reset button the lives appears back. So, how can stop the reset button from affecting the lives.

Any ideas, are there any better of ways of do this ??

Loggis
01-01-2009, 02:12 PM
Currently when you hit the reset button you're just restarting the function thermometer_mc. You'll have to create another function for the reset button which just takes it back down to 0 and has nothing to do with lives. I'm assuming this is the easiest way to do it. Also, you don't need the ; after }.

ilike2
01-01-2009, 03:19 PM
The reset button does take it back to 0 and has nothing to do with the lives.
The "Start" is just a label. Any ideas?

Loggis
01-01-2009, 03:40 PM
Ah, I see the problem. When you reset it, the lives go back up because thermometer_mc goes under 40. What you'll need to do is something like this I'd think //resets the thermometer
drink_btn.onRelease = function() {
if (lives_mc = 3){
gotoAndPlay("start");
} else if (lives_mc = 2){
gotoAndPlay("start_lives_2");
} else if (lives_mc = 1){
gotoAndPlay("start_lives_1");
}


};

//when the thermometer reaches a certain number of frames one live is deducted.
onEnterFrame = function () {
if (thermometer_mc._currentframe == 40) {
lives_mc.gotoAndStop("two_lives");
} else if (thermometer_mc._currentframe == 80) {
lives_mc.gotoAndStop("one_lives");
} else if (thermometer_mc._currentframe == 100) {
lives_mc.gotoAndStop("no_lives");

}
};

and then make the frames "start_lives_2" and "start_lives_1" exactly the same as the normal game but with the correct amount of lives.

ilike2
01-01-2009, 04:22 PM
I still have problems, now when the press the reset button. A life gets Subtracted.

orange gold
01-01-2009, 11:24 PM
I have problems with the lives part. For example if I lose two lives (one life left) then when I click the reset button the lives appears back. So, how can stop the reset button from affecting the lives.

Any ideas, are there any better of ways of do this ??

your code to set how many lives you have gets reset when you goback to that frame... put the code that sets how many lives you have a new very first frame that is only reached at the start so reset doesnt take you to a place where that frame loads again

Bod720
01-02-2009, 01:07 AM
Try this:


lives=3
//resets the thermometer
drink_btn.onRelease = function() {
thermometer_mc.gotoAndPlay("start");
};

//when the thermometer reaches a certain number of frames one live is deducted.
onEnterFrame = function () {
if (thermometer_mc._currentframe >= 40 && thermometer_mc._currentframe < 80) {
lives=2
} else if (thermometer_mc._currentframe >= 80 && thermometer_mc._currentframe <100) {
lives=1
} else if (thermometer_mc._currentframe == 100) {
lives=0
}
lives_mc.gotoAndStop(lives+1)
};


And make your lives_mc have no lives on frame 1, one life on frame 2, 2 on frame 3, and 3 on frame 4.

ilike2
01-02-2009, 01:51 AM
It still has the exact same problem.

For example, when there is only one life left. And I press the reset button two lifes appear.

Bod720
01-02-2009, 02:55 PM
Can you upload your .fla or at least just the lives part.

ilike2
01-02-2009, 03:36 PM
This is just the testing .fla, and not the final game. Btw.

Bod720
01-03-2009, 04:14 PM
Please find the file attached, and feel free to ask me any questions you may have.

ilike2
01-03-2009, 04:31 PM
I figured out a solution this morning, but thanks for the help anyway.

Also, the file you attached doesn't seem to work. Its say "Unexpected file format"

Bod720
01-03-2009, 08:12 PM
OH that must be because of the version of flash you are using. I think I saved it as a CS3 document, but if you tried opening it in CS3 then it must be a CS4 document.