PDA

View Full Version : [AS2] detecting if level is complete


bessy
07-29-2009, 11:09 AM
I am currently making a game with multiple levels. I have a level selection screen and when u complete a level u can go back to this screen. I want to know how to tell the level selection screen that a level is completed.
For example, the level selection screen has multiple grey buttons. When the level one button is clicked you go to level one. When level one is complete u can click the back button to go back to the level selection screen. But when returning to the level selection screen i want the level one button to turn green instead of grey, showing that you have completed the level.
Can anyone please help?

crosshair
07-29-2009, 11:29 AM
This is justa little example if you have buttons with instances of button1, button2 etc.

var curLevel:Number = 5;

this["button"+curLevel].gotoAndStop(2);

Like i said, just an example and you will most likely need to change it.

bessy
07-30-2009, 06:43 AM
sorry i dont quite understand you. this code is for levels in games?

crosshair
08-03-2009, 11:59 AM
I am going to make a little example for you.

crosshair
08-03-2009, 12:11 PM
This will the button that represents the curLevel yellow.
You will most likel need to change it alot to suit your needs.

bessy
08-04-2009, 11:07 AM
I tested the fla. you posted. I actually want all the levels that i have done to turn yellow. For example: on completion of level 5, levels 1 through to 5 will be yellow (provided i have also completed levels 1,2,3 and 4). Can u help?

crosshair
08-04-2009, 01:22 PM
Now green is playable & red is unplayable.
I also made it so that you can only click on the playable levels.

Hope it helps.

bessy
08-05-2009, 07:14 AM
thats great. now ive gotta try and add it to my game...

crosshair
08-05-2009, 12:19 PM
Shouldnt be too hard, if you need it i will be glad to help.

bessy
08-07-2009, 05:38 AM
okay, i have added the code to my game. the levels turn green when playable and the code is working. but, every level button takes me to level 1. when i go back to the level selection screen after completing level 1, level 2 is playable, so i click on the level 2 button and it takes me back to level 1. can u make it so that when i click the level 2 button it takes me to level 2, and also do the same with the other level buttons.

crosshair
08-07-2009, 10:52 AM
Post your fla.

bessy
08-08-2009, 01:07 AM
can u just modify the code to cater for multiple frames. not just take you to the frame of level 1.

crosshair
08-08-2009, 03:26 PM
If you put a frame label on the frame game1 game2 etc then you could change the gotoAndStop to:

gotoAndStop(_root["game"+curLevel]);


You should be able to see how to edit this further.

bessy
08-09-2009, 08:00 AM
should the code on the level select frame look like this:

stop();
var i = 0;
var root = this;

for(i = 1; i <= 10; i++) {
if(i > curLevel) {
this["button"+i].gotoAndStop(2);
}

if(i <= curLevel) {
this["button"+i].onRelease = function() {
gotoAndStop(_root["game"+curLevel]); //The game frame
}
}
}



i have also named the 10 levels game1, game2 etc. when i test it, clicking on the level 1 button doesn't do anything(the other level buttons are grey and cannot be clicked, but this is how it should work). What else do i need to do?

crosshair
08-09-2009, 01:43 PM
this["button"+i].gotoAndStop(_root["game"+i]);

bessy
08-10-2009, 07:39 AM
where does that go?

crosshair
08-10-2009, 11:59 AM
Seriously, you cant always expect everyone to do this stuff for you.
I asked you to upload your fla so i could adjust the code.

bessy
08-12-2009, 01:04 AM
what if i make an example fla, as in have the main menu, levels, level select and all that. Wan't me to do that and post it for you to inspect?