26 Replies Latest reply on Jan 12, 2012 11:57 AM by kglad

    Level select menu

    xmasgame

      Hey,

       

      I'm working on my latest game which have made me learn alot about adobe flash.

      But I have one big problem!

       

      The level select menu...

      I want to make "this" code:

      1. First you select level 1 because thats the only level that isn't locked

      2. You made it thru level 1 and have now got 1x coin which opens level 2!

       

      I want my code to be like that, and I want it also to not be able to give the player a chance to do level 1 more times to get more coins.

      1 coin, each level.

       

       

      At this code.. i would actually like to be lazy and would love if anyone could give me the code because I understand the code you will give me but it might not learn me much about it tho.

      Anyhow if you people want me to learn this insted of just giving me the code, i love like some links etc on where i could learn it as I got some problems on.. what do i need to learn to make it thru, where can i read about it? etc etc

       

      Hope for some nice answers and this is a major prodject for me and i'm really stuck atm, and after this its pretty easy to get done rest is pretty much done.

        • 1. Re: Level select menu
          kglad Adobe Community Professional & MVP

          start your game with a variable (eg, coins) and initialize it to zero:

           

          var coins:int=0;

           

          for your level1 code, check if coins==0:

           

          if(coins==0){

          //allow level1 to be played
          }

           

          when level1 completes, increment coins:

           

          coins++;

           

          now, likewise for level2:

           

          if(coins==1){

          //allow level2 to be played

          }

           

          and, if the same pattern holds for other levels:

           

          // this["level"+(coins+1)] to be played

          1 person found this helpful
          • 2. Re: Level select menu
            xmasgame Level 1

            Hey kglad,

            Thanks for the answer, I will check it out and hopefully it will be "fixed"

            Got a few questions maybe..

            If i put this on my coin frame which i call "counter"

            should i take the diffrent scripts on the object that leads u to the level or the frame it self?

            If its on every object , should it work to do this:

             

            if(coins==1){

            gotoAndStop(2);

            //allow level2 to be played

            }


            As in frame one of the object its "locked" with a animasjon so ppl can see its locked, and in frame 2 of the object its open

             

            If this is hard to understand i will make a file that show this and send it to you.

            Please explain in basic as I'm a noob when it comes to var etc.

            • 3. Re: Level select menu
              xmasgame Level 1

              My counter did not work with:

              counter++;

              but _root.counter +=1; worked.

              Now when it comes back to level screen i got a problem

              I can see the value of counter is 1 but.. it wont effect the object that have this AS:

               

              onClipEvent (enterFrame) {

              if(counter==2){

              this.gotoAndStop(2);

              //allow level2 to be played

              }

              }

               

              I got problem when i tried

              var coins:int=0;

              as well and had to use:

              var counter:Number=0;

              Also by doing

              _root.counter +=1; on the end of the level he gets a +1 score.. BUT! I dont want people to be able to do level 1 and get 1 more point every time.. how i can fix that

              like a true/false that the player have made it.

              • 4. Re: Level select menu
                xmasgame Level 1

                I made it!

                I put the code on the frame insted:

                 

                if(counter==1){

                _root.level2.gotoAndStop(2);

                //allow level2 to be played

                }

                 

                Thanks for the help I was putting the code on every single object but I understood .. that wont work ^^

                 

                Still got 2 problem:

                 

                How do i make it so:

                When i play level 1 and get 1 score im then able to play level 2.

                When i play level 1 or 2 and get 1 more score, level 3 opens BUT level 2 closes because the value is now 2 and not 1.. how can i make level 2 stay open ?

                 


                 

                _root.counter +=1; on the end of the level he gets a +1 score.. BUT! I dont want people to be able to do level 1 and get 1 more point every time.. how i can fix that

                like a true/false that the player have made it.

                • 5. Re: Level select menu
                  kglad Adobe Community Professional & MVP

                  what do you do to start level1?  level2?

                  • 6. Re: Level select menu
                    xmasgame Level 1

                    Assume u dont want this answer

                    but I'm using this

                    Frame 1 starts counter

                    Frame 2 is the main screen (play, levels, info)

                    frame 3 is X

                    Frame 4 is levels

                    Frame 5 is level 1

                    Frame 6,7,8 etc level 2,3,4

                     

                    I'm using the frame 4 aka levels to pick what lvl to choose.

                     

                    To pick levels I'm pressing the button 1,2,3,4 etc on the level screen (frame 4)

                    • 7. Re: Level select menu
                      kglad Adobe Community Professional & MVP

                      when a level is completed, if you're using _root.button1, _root.button2, etc, use:

                       

                      _root.counter++;

                      enableButtonsF();

                       

                      function enableButtonsF():Void{

                      for(var i:Number=1;i<levelNumber;i++){

                      _root["button"+i].enabled=false;

                      }

                      _root["button"+_root.counter}.enabled=true;

                      }

                      1 person found this helpful
                      • 8. Re: Level select menu
                        xmasgame Level 1

                        Ehm...

                        Should I put this on the frame which will end the level for level 1?

                        and the code will be:

                         

                        _root.counter++;

                        enableButtonsF();

                         

                        function enableButtonsF():Void{

                         

                        for(var i:Number=1;i<levelNumber;i++){

                         

                        _root["level2"+i].enabled=false;

                         

                        }

                         

                        _root["level2"+_root.counter].enabled=true;

                         

                        }

                         

                        Sorry for being a noob

                        • 9. Re: Level select menu
                          kglad Adobe Community Professional & MVP

                          no.

                           

                          what are your button names?  _root.level1, _root.level2 etc?

                          • 10. Re: Level select menu
                            xmasgame Level 1

                            Mind if i ask you to help me a little over skype ? so u can see my work and stuff, as I'm making my games maybe abit harder for the scripts to work together then you are used too :s

                            my buttons name are : level1, level2, level3 etc

                            • 11. Re: Level select menu
                              kglad Adobe Community Professional & MVP

                              the only free help i offer is via the adobe forums.  if you want me to fix your files or communicate via phone/email, you'll need to hire me.

                               

                              but for the topic of this thread, you should be able to get all the help you need here:

                               

                              // put the following two lines at the end of each level.

                              _root.counter++;

                              enableButtonsF();

                               

                              // place the below function on frame 1 of your fla.  do not change anything except to assign a value to levelNumber (the total number of your levels)

                              function enableButtonsF():Void{

                              for(var i:Number=1;i<levelNumber;i++){

                              _root["level"+i].enabled=false;

                              _root["level"+i]._alpha = 50;

                              }

                              _root["level"+_root.counter}.enabled=true;

                              _root["level"+_root.counter}._alpha=100;

                              }

                              • 12. Re: Level select menu
                                xmasgame Level 1

                                You miss understand, just want to let you see how i make the game, i mean.. to see where i got the diffrent scripts, how my frames r and such.

                                I dont tell you to do work on it as u cant over skype.

                                 

                                Getting a error:


                                Line 13 (+15 i assume)

                                _root["level"+_root.counter}.enabled=true;

                                _root["level"+_root.counter}._alpha=100;

                                expecting ]

                                 

                                Tried to replace } with ] and then the errors are  gone but the code didn't change anything.

                                • 13. Re: Level select menu
                                  kglad Adobe Community Professional & MVP

                                  that should be:

                                   

                                  // put the following two lines at the end of each level.

                                  _root.counter++;

                                  enableButtonsF();

                                   

                                  // place the below function on frame 1 of your fla.  do not change anything except to assign a value to levelNumber (the total number of your levels)

                                  function enableButtonsF():Void{

                                  for(var i:Number=1;i<levelNumber;i++){

                                  _root["level"+i].enabled=false;

                                  _root["level"+i]._alpha = 50;

                                  }

                                  _root["level"+_root.counter].enabled=true;

                                  _root["level"+_root.counter]._alpha=100;

                                  }

                                  • 14. Re: Level select menu
                                    xmasgame Level 1

                                    Well, if thats correct .. something is wrong as I dont notice anything of the code in the game.

                                     

                                    function enableButtonsF():Void{

                                    for(var i:Number=1;i<3;i++){

                                    _root["level"+i].enabled=false;

                                    _root["level"+i]._alpha = 50;

                                    }

                                    _root["level"+_root.counter].enabled=true;

                                    _root["level"+_root.counter]._alpha=100;

                                    }

                                     

                                    As 3 is the levels i got at the moment (while only level 1 is actually made) but got buttons for 3 levels.

                                    • 15. Re: Level select menu
                                      kglad Adobe Community Professional & MVP

                                      is this executing:

                                       

                                      _root.counter++;

                                      enableButtonsF();

                                       

                                      and, did you initialize _root.counter (=0)?

                                      • 16. Re: Level select menu
                                        xmasgame Level 1

                                        How do i know if its executing ? I know that the frame it is on, is being "read"

                                        First frame on the Fla have this code:

                                         

                                        var counter:Number=0;

                                         

                                        function enableButtonsF():Void{

                                         

                                        for(var i:Number=3;i<levelNumber;i++){

                                         

                                        _root["level"+i].enabled=false;

                                         

                                        _root["level"+i]._alpha = 50;

                                         

                                        }

                                         

                                        _root["level"+_root.counter].enabled=true;

                                         

                                        _root["level"+_root.counter]._alpha=100;

                                         

                                        }

                                         

                                         

                                        This code should be executed but no idea if works, it is on a frame that I know have been working before with another script.

                                        _root.counter++;

                                        enableButtonsF();

                                        • 17. Re: Level select menu
                                          kglad Adobe Community Professional & MVP

                                          where's levelNumber defined?

                                           

                                          and, you should use the trace() statement to confirm that code is executing.

                                          • 18. Re: Level select menu
                                            xmasgame Level 1

                                            My bad, I sent wrong code.. i'm only needed to change "levelNumber" with the number of lvls, right?

                                            like this:

                                            for(var i:Number=1;i<10;i++){

                                             

                                            Never used trace :s

                                             

                                            So sorry for all this problems you got to help me with kglad.

                                            • 19. Re: Level select menu
                                              kglad Adobe Community Professional & MVP

                                              yes, either define levelNumber

                                               

                                              var levelNumber:Number=10;

                                               

                                              or replace it with a number like you did.

                                               

                                              and the trace() function is, by far, the most important actionscript debugging tool.  learn to use it.   there are very few issues in which the trace() function is not key to resolving the issue.

                                               

                                              (and, mark response 13 as the correct response.)

                                              1 person found this helpful
                                              • 20. Re: Level select menu
                                                xmasgame Level 1

                                                Okey thanks, I have marked the response (Didn't wanna do it so people/you thought I was finished )

                                                 

                                                Either way .. I will learn trace soon but I forgot my .Fla file on another computer so... it will take me two weeks maybe before I get it back.


                                                Will tell how it went

                                                • 21. Re: Level select menu
                                                  kglad Adobe Community Professional & MVP

                                                  you're welcome.

                                                  • 22. Re: Level select menu
                                                    xmasgame Level 1

                                                    all my trace says when I have:

                                                    trace(enableButtonsF)

                                                    is "[type Function]"

                                                     

                                                     

                                                    By the way what do "level" mean in this code ? trace say its undefined and didn't you tell me not to write anything else there?

                                                     

                                                    _root["level"+i].enabled=false;

                                                     

                                                    _root["level"+i]._alpha = 50;

                                                     

                                                    }

                                                     

                                                    _root["level"+_root.counter].enabled=true;

                                                     

                                                    _root["level"+_root.counter]._alpha=100;

                                                     

                                                    }

                                                    • 23. Re: Level select menu
                                                      xmasgame Level 1

                                                      As i always do.. I found a way around the hole **** AS that I really got to learn..

                                                      If I let my levelmenu stay thru all frames but only by using AS, i have the panel visible at frame 4, by having:

                                                       

                                                      (this objects to the lvl menu)

                                                      level1._visible = false

                                                      level2._visible = false

                                                      level3._visible = false

                                                      stop1._visible = false

                                                      stop2._visible = false

                                                      levels._visible = false

                                                      bglvl._visible = false

                                                       

                                                      Then on frame 4 I have:

                                                      level1._visible = true

                                                      level2._visible = true

                                                      level3._visible = true

                                                      stop1._visible = true

                                                      stop2._visible = true

                                                      levels._visible = true

                                                      bglvl._visible = true

                                                       

                                                       

                                                      This is btw on two diffrent layers.

                                                       

                                                      Call it a stupid way to do it.. but it works atleast

                                                       

                                                      Level are all open 24/7 after you open them.

                                                       

                                                      BUT the second major problem is still here!

                                                      - how do i make it so people cant repeat level 1 for more score points to unlock next lvls .. hmm

                                                       

                                                      Btw i tried:

                                                      if(counter==0){

                                                          _root.counter +=1;

                                                      }

                                                      I hoped that this AS would say that "if counter is 0, give it a 1+ ((if its over 0, it wouldn't give).

                                                      Sounded to good to be true as I found out it didn't work

                                                      • 24. Re: Level select menu
                                                        kglad Adobe Community Professional & MVP

                                                        if you use:

                                                         

                                                        _root.counter++;

                                                        enableButtonsF();

                                                         

                                                        only the button corresponding to the counter value will be enabled.  so, to start your game:

                                                         

                                                        _root.counter=1;

                                                        enableButtonsF();

                                                         

                                                        // then only _root.level1 button will work so they can only play level 1.  as soon as level 1 is completed, you should execute:

                                                         

                                                        _root.counter++;

                                                        enableButtonsF();

                                                         

                                                        // then only _root.level2 button will work so they can only play level2.  etc

                                                        • 25. Re: Level select menu
                                                          xmasgame Level 1

                                                          Sorry mr.kglad, your AS is impossible for how I have buildt my game I believe but I have figured a way around again..

                                                          1. I finish at goal

                                                          2. a AS in my goal says to another object : go to next frame and in that frame i get a + in the counter.

                                                          2. When the player do level 1 again.. nothing will happen as this frame with the + to counter are already triggered

                                                           

                                                          Thanks for the help tho kglad, you have made me getting thru but again, I know I got to learn more AS. Even tho I would say i thinked out some good "walk around" objects

                                                          • 26. Re: Level select menu
                                                            kglad Adobe Community Professional & MVP

                                                            you're welcome.