A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help with a scoring system.

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    5

    Help with a scoring system.

    Resolved!!!


    I have been working on a flash game for quite some time now and i want to add a scoring system at the end.
    I have a dynamic text box that shows the final score which has no problems allthough i tried to make another text box that gives you your 'rank'.
    what i mean by this is lets say you score between 1 and 100 points the text box shall say 'you were crap' and if you got between 101 and 200 points it would say 'Dont quit your day job' and so on and so forth. but...
    i have no idea on how i can do this so i come asking for flashkits scripters to help me.

    my coding is this (goes on the layer):
    Code:
    txtFinalScore.text = 'Final Distance: '+score +' Meters';
    txtFinalRank.text =
    the txtFinalScore is the final score you get and the txtFinalRank you get is the speach.

    Also because i dont want to go on forever iwould like it to say something like 'You are Dino Raptor Jesus' if you get a score of over lets say 10000 that way i can leave it like that and not have to add millions of 'ranks'.

    Thanks in advance im using Adobe Flash CS4 with ActionScript 2.

    Cralant.
    Last edited by Cralant; 11-22-2009 at 07:44 PM.

  2. #2
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26

    resolved

    Try this:

    Code:
    If (score > 0 && score <= 100) {
        txtFinalRank.text = "You're a beguinner. Keep trying.";
    } else if (score > 100 && score <= 200) {
        txtFinalRank.text = "Not enough. Do your homework.";
    /* AND SO ON, YOU CAN ADD AND ADAPT THESE TWO LINES AS FAR AS YOU WISH:
    } else if (score > 200 && score <= 300) {
        txtFinalRank.text = "Not enough. Do your homework.";
    */
    }
    Tell me if it works.
    One idea. One emotion. One project.

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    5

    Unhappy still not working

    Im not sure where i am ment to put this but i put it on the layer containing the dynamic text box and that does not work it gives me the errors:

    Location || Description || Source

    Scene=Scene 1, layer=actions, frame=4, Line 11 || Syntax Error || If (score > 0 && score <= 100) {

    Scene=Scene 1, layer=actions, frame=4, Line 13 || 'else' encountered without matching 'if'' || } else if (score > 100 && score <= 200) {

    The actions on my layer are:
    Code:
    stop();
    
    _root.onEnterFrame = function(){ 
    	if(Key.isDown(32)){
    		gotoAndPlay(2);
    	}
    }
    
    If (score > 0 && score <= 100) {
        txtFinalRank.text = "Dude you suck";
    } else if (score > 100 && score <= 200) {
        txtFinalRank.text = "Not enough. Do your homework.";
    /* AND SO ON, YOU CAN ADD AND ADAPT THESE TWO LINES AS FAR AS YOU WISH:
    } else if (score > 200 && score <= 300) {
        txtFinalRank.text = "Not enough. Do your homework.";
    */
    }
    So yeah it does not work i can give you a 'test' flash if you would like one.

  4. #4
    Programmer
    Join Date
    Aug 2007
    Posts
    173
    //create a new layer.
    //add a key frame where the score page is.
    //place this on the frame

    Code:
    selectedRank = 0
    rank0 = ""
    rank1 = "you suck"
    rank2 = "realy?"
    rank3 = "hmmm try again?"
    //ect
    
    if(score < 100){
    	selectedRank = 1
    }
    if(score >= 100){
    	selectedRank = 2
    }
    if(score >= 150){
    	selectedRank = 3
    }
    //ect
    
    txtFinalScore.text = 'Final Distance: '+score +' Meters';
    txtFinalRank.text = _root["rank"+selectedRank]
    this method lets you easily add and change your rank responses, as they are set to variables.

    hope this helps ^^
    Freelance: AS2, AS3, PHP, MySQL, JavaScript
    Skype: hunty93

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    5

    resolved Im a donut.

    Im sorry for wasting your time i just realised that i gave the instance name 'txtFinalank' when it was ment to of been 'txtFinalRank' on the dynamic text box.
    Both methods worked perfectly just my foolish mistakes wasted time.
    Thank you.

    Cralant

  6. #6
    Cancerbero
    Join Date
    Jan 2003
    Location
    Mexico City.
    Posts
    26
    My mistake:

    At the very begining of my code I wrote "If", but it should be "if".

    Sorry.

    I see hunty93's answer is better than mine because is very clear and is dynamic.

    He uses _root["rank"+selectedRank] to make your life easier. When you use this[] or _root[], you're able to transform strings plus variables to pieces of code.

    So, in each case, hunty93's code becomes:

    txtFinalRank.text = rank0; // ""
    txtFinalRank.text = rank0; // "you suck"
    txtFinalRank.text = rank0; // "realy?"
    txtFinalRank.text = rank0; // "hmmm try again?"
    One idea. One emotion. One project.

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