dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Newb needs help with cross-scene variables.

  1. #1
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11

    [Help] Newb needs help with cross-scene variables.

    Ok, heres what I want to do:

    I have 2 variables controlling the rate of fire and the amount of enemies(based on a tutorial here).
    I've added health etc so far.

    What i really want to do is have a control on the start page of the game which controls the two variables, changing the difficulty.

    I figured an input text could do the trick, but I'm not sure how to change a variable using one.

    The problem is, the start page is on another scene to the actual game, and I don't know the rules about cross-scene variables.

    Any help would be really appreciated.

    Thanks.
    Last edited by Sayum; 05-10-2004 at 04:45 PM.

  2. #2
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    For the input box, have a button next to it, on(press){ var1 = var you used on input box, etc...

    It should hold up to the next scene, I do not use scenes. It would be better to have two buttons, easy and hard, rather than letting the player enter whatever they want.

    code:

    on(press){
    if(difficulty == hard){
    _root.enemySpeed = 3;
    }
    else if(difficulty == easy){
    _root.enemySpeed = 1;
    }
    }



    With separate buttons, one would have:
    code:

    on(press){
    _root.enemySpeed = 3;
    _root.gotoAndStop("beginning");
    }

    Last edited by kendude; 05-10-2004 at 03:52 PM.

  3. #3
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11
    Wow, having 100s of members online really helps out.

    I'm gonna try and move the first scene onto the second and use the stop() command. Thanks for the help, I'll get right back here with the results.

  4. #4
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11
    Hmm, it didnt seem to work. I moved the first scene onto the second but i guess the variables weren't defined. To sort that out i moved the "control" layer to where it would work.

    But nothing changes when I click easy OR hard, both play exactly as it was before.

    Oh, I'm using numEnemy now to change the amount of enemies.

    Edit: the buttons controlling difficulty are on a different layer to everything else if that changes things.

    I could email you the source if I'm making no sense...
    Last edited by Sayum; 05-11-2004 at 10:46 AM.

  5. #5
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    Layers do nat affect it.
    difficulty = "whatever";//declared initially
    code:

    on(press){
    _root.difficulty = "easy";
    }


    Then on another button:
    code:

    on(press){
    _root.difficulty = hard";
    }


    Then on yet another button:
    code:

    on(press){
    trace(difficulty);
    }


  6. #6
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11
    All that did was tell me what the current state was.

    It was too big to upload, I'm uploading it to a server. Maybe that can help, I'm terrible at explaining.

    http://sayum.oddrealm.net/Flash/leechthegame.fla

  7. #7
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    What you have:
    code:

    if (this.difficulty = 1){
    numEnemy = 20;
    }
    if (this.difficulty = 2){
    numEnemy = 1;
    }





    What you need:
    code:

    if (this.difficulty == 1){
    numEnemy = 1;
    }
    if (this.difficulty == 2){
    numEnemy = 20;
    }


  8. #8
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11
    Thanks man, that sorted the problem out perfectly. Thanks.

    Edit: slight problem, if you choose the "Hard" difficulty, die and click restart, the enemies are still moving and carry on to the "easy" difficulty.
    Last edited by Sayum; 05-12-2004 at 01:53 PM.

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Originally posted by Sayum
    slight problem, if you choose the "Hard" difficulty, die and click restart, the enemies are still moving and carry on to the "easy" difficulty.
    You would need to remove the duplicated enemies. In the gameover frame add:
    code:

    for (i=2; i<=numEnemy; i++){
    removeMovieClip( "enemy"+i);
    }


  10. #10
    Junior Member
    Join Date
    May 2004
    Location
    Florida
    Posts
    11
    Once again, thanks for the help! I'm glad I found a decent community!

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