A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: comparing arrays and loops

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3

    comparing arrays and loops

    Hi there, this is my second flash project and i am having an absolute nightmare trying to get the last part to work. please excuse the explaination, if anyone wants to see the full code i would really appreciate your help.

    The scenario is to create a lotto game that matches 6 user inputted numbers with 7 randomly generated numbers. The 7th number is a special case (eg bonus ball)


    ANY HELP REALLY APPRECIATED!!! WOULD LIKE TO SHOW A KIND HEARTED FALSH GENIUS ALL OF THE SCRIPT IF POSS! (its not tooo long)

    This code works, but it just outputs the default message:
    There seems to be a problem with my arrays not comparing?
    Part of the code is: (prioir to this the user inputs numbers, they are copied to text areas beginning with O, on a button press) On a second button press randomly generated number appear to a timer.

    //compareResult checks how many numbers match between the two sets of numbers to determine winnings.
    function compareResult(user, machine, b) {
    var i: int = 0;
    var c: int = 0;
    var matchcount: int = 0;
    var bonusMatch: Boolean = false;
    while (i<=5) {
    c = 0;
    while (c<=5) {
    if (user[i] == machine[c]) {
    matchcount++;

    }
    if (user[i] == machine[6]) {
    bonusMatch = true;
    }
    c++;
    }
    i++;
    }
    if (b == true) {
    return matchcount;
    } else {
    return bonusMatch;
    }
    }

    var results:Array = new Array();
    var b:Boolean = false;
    var a: int;

    //puts draw numbers into an array - these are TEXT AREAS not converted to int is this the problem?

    var drawResult:Array = new Array (R1,R2,R3,R4,R5,R6,R7);

    //puts user chosen numbers into array these are TEXT AREAS not converted to int is this the problem?

    var selectedNumbers:Array = new Array (O1,O2,O3,O4,O5,O6);
    b = true;
    var matchNum: int = compareResult(selectedNumbers, drawResult, b);
    b = false;
    var bonus:Boolean = compareResult(selectedNumbers, drawResult, b);

    var resultStat:int = 0;

    //winningMsg displays a message depending on what the user has won.
    function WinningMsg(matchNums, bonus) {

    if (bonus == true) {
    switch (matchNums) {
    case "4" :
    Win.visible = true;
    Win.text="You have matched 3 numbers and the bonus ball win loads";
    break;

    case "5" :
    Win.visible = true;
    Win.text="You have matched 4 numbers and the bonus ball win loads n loads";
    break;

    case "6" :
    Win.visible = true;
    Win.text="JACKPOT matched 5 numbers and the bonus ball";
    break;

    default :
    Win.visible = true;
    Win.text = "no luck this time"

    ;
    }
    }
    if (bonus == false) {
    switch (matchNums) {
    case "3" :
    Win.visible = true;
    Win.text="You have matched 3 numbers and won a tenner";
    break;

    default :
    Win.visible = true;
    Win.text = "no luck this time";
    }
    }

    }

    I have a feeling i'm doing completely backwards! pleeeeeease help! deadline approaching fast and stress levels near breaking computer point!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function compareResult(user, machine, b) {
    	var i:int = 0;
    	var c:int = 0;
    	var matchcount:int = 0;
    	var bonusMatch:Boolean = false;
    	while (i<=5) {
    		c = 0;
    		while (c<=5) {
    			if (user[i].text == machine[c].text) {
    				matchcount++;
    
    			}
    			if (user[i].text == machine[6].text) {
    				bonusMatch = true;
    			}
    			c++;
    		}
    		i++;
    	}
    	if (b == true) {
    		return matchcount;
    	} else {
    		return bonusMatch;
    	}
    }
    
    var results:Array = new Array();
    var b:Boolean = false;
    var bonus:Boolean = false;
    var a:int;
    var matchNum:int;
    var resultStat:int = 0;
    
    
    var drawResult:Array = new Array(R1,R2,R3,R4,R5,R6,R7);
    var selectedNumbers:Array = new Array(O1,O2,O3,O4,O5,O6);
    b = true;
    matchNum = compareResult(selectedNumbers,drawResult,true);
    WinningMsg(matchNum, bonus);
    b = false;
    bonus = compareResult(selectedNumbers,drawResult,true);
    
    WinningMsg(matchNum, bonus);
    
    function WinningMsg(matchNums, bonus) {
    	trace(matchNums);
    	if (bonus == true) {
    		switch (matchNums) {
    			case 4 :
    				Win.visible = true;
    				Win.text = "You have matched 3 numbers and the bonus ball win loads";
    				break;
    
    			case 5 :
    				Win.visible = true;
    				Win.text = "You have matched 4 numbers and the bonus ball win loads n loads";
    				break;
    
    			case 6 :
    				Win.visible = true;
    				Win.text = "JACKPOT matched 5 numbers and the bonus ball";
    				break;
    
    			default :
    				Win.visible = true;
    				Win.text = "no luck this time";
    				break;
    		}
    	} else if (bonus == false) {
    		switch (matchNums) {
    			case 6 :
    				Win.visible = true;
    				Win.text = "You have matched 3 numbers and won a tenner";
    				break;
    
    			default :
    				Win.visible = true;
    				Win.text = "no luck this time";
    				break;
    		}
    	}
    
    }

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    3

    Thanks but more suggestions needed

    thanks but that didnt work. It made the text area Win visible from start up and when i tested the output only "no luck this time" appeared

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    I also get the following in the output window
    36
    36
    0
    0
    0

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Can you post a stripped down version of your fla here?

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