A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How do I run a script until changing path?

  1. #1
    Junior Member
    Join Date
    Dec 2014
    Posts
    2

    How do I run a script until changing path?

    I have a page I'm playing with. It's a very simple game with letters and numbers for my grandson (yes, I'm that old).
    On a scene called MENU I can press a button to start. This button takes me to a scene called RANDOM.
    This page will make a random number to take me to a random page. Either GAME1, GAME2, GAME3, and so on.
    Here I want to make a count++. I also want it to check if the number have reached 5. Then it should take me to a bonus scene called BONUS.
    If it haven't reached number 5, then it should just continue the script and load the random scene (GAME1, GAME2 or whatever).
    When I press a letter or number on GAME1 it will either reload the same scene for another try or, if you press the correct letter it will move me to RANDOM to add 1 to the number of tries.
    But I can't make it work the way I want.

    On the MENU I have this code to set things to 0.
    var count:Number = 0;

    On the RANDOM scene I have this code on the first frame.
    var maxTimesToPlay:Number = 5;
    count++;
    count_txt.text = count;

    if(count == maxTimesToPlay){
    gotoAndPlay('BONUS');
    }else{
    HERE I HAVE ALL THE RANDOM PARTS
    }

    And on the Game pages I have a code on the Letter or Number that is the correct one.
    So if you press D, which is the correct one on GAME1, then I have this code:

    on (release) {
    gotoAndStop('RANDOM');
    }

    But there must be something wrong. Since it doesn't stop after 5 times.
    I have tried to change things a lot of times and found some code here and there.
    I'm not at home right now and not sure if this is the latest code I did use. But it is something like that.
    Can anyone see what is wrong or maybe a better way to get it right?

    I'm definitely a newbie.

  2. #2
    Member
    Join Date
    Sep 2014
    Posts
    75
    hello,

    to be honest, I did not quite get what really the game is about, however, check out the the following comment lines inside the code, it might be useful(not sure).


    if(count == maxTimesToPlay){

    //the code here will work ONLY if "count=5"

    gotoAndPlay('BONUS');

    }else{

    //while the code here will continue working as long as "count not equal to 5"
    //it will work when "count less than 5", and when "count more than 5".

    HERE I HAVE ALL THE RANDOM PARTS
    }

    good luck!

  3. #3
    Junior Member
    Join Date
    Dec 2014
    Posts
    2
    Well. The game isn't ready. But if the user is clicking on a letter in the game it will continue to run until it reaches 5 correct answers. So, when count == 5 it is supposed to go to the bonus game. So that is correct.
    But the code I wrote isn't working. It won't change when it reach 5. So what is wrong in my code?

  4. #4
    Member
    Join Date
    Sep 2014
    Posts
    75
    hi,

    try using gotoAndStop("BONUS"); instead of gotoAndPlay('BONUS');
    because when you "gotoAndPlay" the scene will jump to the frame called "BONUS" but won't stop there. if you use "gotoAndStop" the scene will jump and stop on the page/scene where the " bonus game" is. Using "gotoAndStop" doesn't mean that the game will stop, it mean stop at frame named "BONUS". Also use "BONUS" instead of 'BONUS'.

    hopefully that will work,

    good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center