A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Score Limit (Dynamic Text Field)

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    7

    Exclamation Score Limit (Dynamic Text Field)

    I have a dynamic text field that tracks score, I don't want it going above 2,500,000 (2.5 million) = 25000000.
    Is there any way to set a limit so when it reaches 25000000, even if score gets added to it that would put it thousands over the limit, to stop it or take it back to 25000000?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Maybe something along the lines of
    PHP Code:
    var maxScore:Number 2500000;
    if (
    score >= maxScore)
    {
        
    score maxScore;


  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Doesn't seem to be working... Had a quick mess with the code trying different names and placements etc, didn't get it to work.

    Oh, I'm working with AS2 by the by... Forgot to put that when I launched this thread because I was tired, sorry!
    Last edited by X864; 08-21-2014 at 11:05 PM.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    That is AS2 , try showing some code or attaching your *.fla

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Quote Originally Posted by fruitbeard View Post
    Hi,

    That is AS2 , try showing some code or attaching your *.fla
    Well, I have a score counter with the var "score" (no instance name), and I have it go to 0 at the start of each new game with the command line "_root.score = _root.score = 0" (it has the _root.'s because it is reset via a movie clip). Then throughout the game I add to it with a command triggered by buttons and the like with "_root.score = _root.score +450" etc. Can't really attach the fla. as the counter is in a large and complex game. I could strip it out and put it in a blank fla file, but I do feel this is a bit unnecessary really when all we're working with here is a dynamic text field and a button which adds score. I just want it so it can't add score above 25000000, and it has to be that specific maximum number, I know it sounds high but there's no other way.

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    However you have your game set up or whenever you add or subtract score, try calling a function


    somethihg like so
    PHP Code:
    score += intended score;
    doScore();

    var 
    maxScore:Number 2500000;
    function 
    doScore()
    {
        if (
    score >= maxScore)
        {
           
    score maxScore;
        }


  7. #7
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Alright I'll have a play around with this, sorry it took me so long to get back to you and confirm it as having not worked or having worked. Just a bit busy these days. I'll be testing it tomorrow, and you'll get a mention if it works, of course! Because this is quite a vital element in the score engine.

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    It will work if you use it in the correct pace, I find it hard to comprehend that if you have an already large and complex game that you are unable to achieve this.

    if you still have problems try attaching a mock version of what it is you wish to achieve so we can correct it for you

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Example

  10. #10
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Example
    That's an amazing example, I still haven't gotten around to perfecting the score system, so I'm not sure if I can get it working yet, but that fla. file is sadly incompatible with my Flash 8 version, I'm guessing that's a CS4 or above fla. So I can't see the code you used :C
    As long as it's possible it should be okay, though! Thanks for your support.

    The reason why I can't do this sort of thing is because of the nature of the game, which is mostly movie clip driven and button driven. I'm not a coder, I'm a graphical person, this game is highly graphical and very tangible on the stage, and clicky, not so much codey.

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    It was CS5, as low as I can save

    Basically with a button and two text fields, the names are in the code

    PHP Code:
    var maxScore:Number 2500000;
    var 
    scoreCapped:Number 0;
    var 
    scoreNormal:Number 0;

    var 
    scoreToAdd:Number 258023;// just a random number

    addButton.onPress = function()
    {
        
    scoreCapped += scoreToAdd;
        
    scoreNormal += scoreToAdd;
        
    doScore();
    };

    function 
    doScore()
    {
        if (
    scoreCapped >= maxScore)
        {
            
    scoreCapped maxScore;
            
    trace("Maximum score reached");
        }
        
    scoreTextCapped.text String(scoreCapped);
        
    scoreTextNormal.text String(scoreNormal);


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