A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 38

Thread: multiple hit tests in one line?

  1. #1
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610

    multiple hit tests in one line?

    Hi,

    I have a scoreboard with numbers 20 - 15 plus bullseye. The scoreboard contains 3 MC's (lights) for each number
    (20=mark201,mark202,mark203,etc...). On the main stage, I have 3 darts. Trying to test if a dart hits, to light up the first "mark201". I can do that with an invisible hit clip over the 20 segment like this.......


    Code:
    onClipEvent (enterFrame) {
        if (this.hitTest(_root.dart1.anim1.hit1)==true|this.hitTest(_root.dart2.anim2.hit2)==true|this.hitTest(_root.dart3.anim3.hit3)==true) {
            _root.mark201.gotoAndStop("on");
        }
    }

    How can I increment the lights based on dart hits? I have tried setting a variable in each of the lights to "unlit" and "lit" and then set it to this, but it does not work.........

    Code:
    onClipEvent (enterFrame) {
        if (this.hitTest(_root.dart1.anim1.hit1)==true|this.hitTest(_root.dart2.anim2.hit2)==true|this.hitTest(_root.dart3.anim3.hit3)==true) {
            _root.mark201.gotoAndStop("on");
        } else if (_root.scoreboard.mark201==lit&&this.hitTest(_root.dart1.anim1.hit1)==true|this.hitTest(_root.dart2.anim2.hit2)==true|this.hitTest(_root.dart3.anim3.hit3)==true) {
            _root.mark202.gotoAndStop("on");
        }
    }

    Any suggestions as to how better to approach this?
    Thanks for looking!
    Regards
    ~GD~
    Operator Error

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    urghhh!!!!!!!

    Code:
    onClipEvent (enterFrame) {
        for (i=1;i<3;i++) {
            if(this.hitTest(_root["dart"+i]["anim"+i]["hit"+i] == true)) {
                _root.mark201.gotoAndStop("on");
            }
        }
    }
    For the bottom one increment a value in a function!
    Code:
    nextLight = function() {
        var j=1
        _root["dartLight"+j].gotoAndStop('on')
        j++
    }
    RipX
    Last edited by RipX; 07-27-2003 at 10:56 AM.

  3. #3
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thx for that, I knew there was a better way to code this. I have tried
    to add the for loop and increment that way, but I still can't seem to get it. I can't even get the first light to appear now. The code makes sense, it should increment the dart num, anim num, and hit num by one after a "hit". It should then tell the first mark20... (mark201) to go to and stop at "on" and increment that number by one with each hit, ie..... mark202, mark203. This code and some to add points to the score if the mark is closed should be almost the whole code for each single hit segment.

    This is the way I would like to do it, much better than the sloppy coding for the hit test I was trying. Is there something in the way I have this coded out that would be an obvious problem?
    Code:
    onClipEvent (enterFrame) {
        for (i=1; i<3; i++) {
            if (this.hitTest(_root["dart"+i]["anim"+i]["hit"+i] == true)) {
                nextLight = function () { var j = 1;_root.scoreboard["mark20"+j].gotoAndStop('on');j++;};
            }
        }
    }
    The hit test I was using would send the first mark20 to "on". Am I not using this correctly?

    Thx for looking
    ~GD~
    Operator Error

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    errrr, no - you need to go and learn the basics of flash in the AS dictionary!!!

    look at variables, movieclips and functions!

    RipX

  5. #5
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    That is what I have been doing for the past hour or so just on your code. I have a few flash books, but they have not shown me how to code dynamically in the way that I see many here code. Thanks for the suggestion though.

    GD
    Operator Error

  6. #6
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    do it in the timeline, not in a clip....
    Code:
    onEnterFrame = function() {
        for (i=1; i<3; i++) {
            if (BOARD_PART.hitTest(_root["dart"+i]["anim"+i]["hit"+i] == true)){
                nextLight()
            }
        }
    }
    nextLight = function () { 
        var j = 1;
        _root.scoreboard["mark20"+j].gotoAndStop('on');
        j++;
    };
    Although it would be better to not check this every frame! Rather just when it makes contact with the dart board!!!

    RipX

  7. #7
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    you dont even need to do all the darts in a loop, just increment the dart number, as your thowing them!! Even better, work out where it's going to land using the same math your using for the darts, that way you have no hitTesting at all!

    RipX

  8. #8
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    No hit testing was one of the ways I was approaching this. Basically, I am trying to learn how many of you code here dynamically. I do not understand coding strictly on the main timeline. My first intro to flash was flash 5 and as I learned things, I coded almost everything on MC's or buttons. Using functions, for loops and many AS actions are brand new to me. I tried to do this dynamically and several folks have pointed me to how to do this. I am peddleing as fast as I can but the hill seems rather steep to me. The hit test method I understand to a degree. Not as well as some of the game coders posts I read here, but I thought well enough to do it that way. Dynamically, Jonmack, tonypa, and marshaldabeachy have all had great ideas! If I was a decent coder, I would do it the way they have suggested, and you, with math and no hit testing. Here is a code that pretty much works for a 301 or 501 game that I was trying to adapt to cricket, but like I said, I simply do not understand the concepts behind this code. I am studying it, but I also want to continue with things to feel like I am making some progress.
    Code:
    scores = [0, 0, 15, 0, 17, 0, 19, 0, 16, 0, 0, 0, 0, 0, 0, 20, 0, 18, 0, 0];
    dists = [4, 11, 56, 62, 94, 102];
    offset = -(360/scores.length)/2;
    function land(dart) {
        if (myDart>3) {
            newTurn();
        }
        myDart++;
        var distx = int(dart.x)-_root.board._width/2;
        var disty = int(dart.y)-_root.board._width/2;
        trace(distx);
        trace(disty);
        var dist = Math.sqrt(distx*distx+disty*disty);
        var angle = Math.atan2(disty, distx)*180/Math.PI;
        trace(dist);
        if (dist<dists[0]) {
            // double bullseye
            points = 50;
        } else if (dist<dists[1]) {
            // bullseye
            points = 25;
        } else if (dist<dists[dists.length-1]) {
            if (angle-offset<0) {
                angle += 360;
            }
            var points = scores[Math.floor((angle-offset)/(360/scores.length))];
            if (dist>dists[2] && dist<dists[3]) {
                points *= 3;
            } else if (dist>dists[4] && dist<dists[5]) {
                points *= 2;
            }
        } else {
            points = 0;
        }
        totalScore += points;
        total = "Total: "+totalScore+" Points";
        output = points+" Points!";
    }
    function newTurn() {
        dartNum = 1;
        totalScore = 0;
    }
    newTurn();
    newDart();
    This nice code is from Marshall. I have your code and I will study it more! Your code makes sense and looks to be what I need to learn how to do for the hit test method. Thanks for the suggestions.

    Regards
    ~GD~
    Operator Error

  9. #9
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Code:
    // The scores around the board - need to be corrected
    scores = [0, 0, 15, 0, 17, 0, 19, 0, 16, 0, 0, 0, 0, 0, 0, 20, 0, 18, 0, 0];
    // Distances of the trebles and doubles etc ???
    dists = [4, 11, 56, 62, 94, 102];
    offset = -(360/scores.length)/2;
    function land(dart) {
    // Defines max 3 darts
        if (myDart>3) {
    // Activates the next go function
            newTurn();
        }
    // Increments the dart number ie 1,2,3
        myDart++;
    // Figures the distance from the center of the board!
        var distx = int(dart.x)-_root.board._width/2;
        var disty = int(dart.y)-_root.board._width/2;
    // Traces the above results in TEST MOVIE option
        trace(distx);
        trace(disty);
    // Works out the angle to throw in
        var dist = Math.sqrt(distx*distx+disty*disty);
        var angle = Math.atan2(disty, distx)*180/Math.PI;
    //
        trace(dist);
    // Check if the dart is in the bullseye by looking at the first ellement in the dists array
        if (dist<dists[0]) {
            // double bullseye
            points = 50;
    // Same as last comment except for the outer bull
        } else if (dist<dists[1]) {
            // bullseye
            points = 25;
        } else if (dist<dists[dists.length-1]) {
            if (angle-offset<0) {
                angle += 360;
            }
    // Get the scroe from the scores array based on the angle
            var points = scores[Math.floor((angle-offset)/(360/scores.length))];
    // Figure out if you hit a treble from the dists array
            if (dist>dists[2] && dist<dists[3]) {
                points *= 3;
    // Figure out if you hit a double from the dists array
            } else if (dist>dists[4] && dist<dists[5]) {
                points *= 2;
            }
        } else {
            points = 0;
        }
    // Add the score to the totalScore variable
        totalScore += points;
        total = "Total: "+totalScore+" Points";
    // Show your last score
        output = points+" Points!";
    }
    reset the everything!
    function newTurn() {
    
        dartNum = 1;
        totalScore = 0;
    }
    // Activate the functions
    newTurn();
    newDart();

  10. #10
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thank you for the excellent comments on the code. It took me some time to understand it all,and many explanations from Marshall, but I do understand what that code does. I tried for some time to manipulate it with a scoreboard function that would accomodate a "cricket" dart game. Just understanding the trig math behind ...

    var dist = Math.sqrt(distx*distx+disty*disty);
    var angle = Math.atan2(disty, distx)*180/Math.PI;

    took me some time and research here....
    http://www.projectalevel.co.uk/maths/

    I have researched pythagora's theroem, radians, converting degrees to radians and vice versa, area of a sector, calculating the distance from the dart to the bull with math sqr root, determining the score through the score array with math floor, .... all new to me and so very impressive that someone could write this code in 20 minutes that I have looked into for 3 weeks.

    Obviously there are many here that are quite good at coding and understanding actionscript methods. It appears you are one of them. I am not trying to waste anyone's time. I am trying to learn from this, and I have learned a great deal already. Many new things. Naming methods, arrays, functions, localToGlobal,etc...

    Marshall explained how I could pull the scores from the board and set the "lights" dynamically, that is what I have been trying to manipulate. I find it confusing so I was trying the hit test method with MC's to power the scoreboard. It would take alot of MC's that way, one for each single, double, and triple segment, plus the bullseye, but I understand the dynamics of that a bit better than adapting the posted code right now.

    "You can pull the score from the dart board. You can also determine the number of lights based on the total score with Math.floor(totalScore/score);. Your final equation would be something like this:

    Code:
    var score = board.score; 
    _root.scoreboard["mark"+score+"-"+Math.floor(totalScore/score)];
    Marshall"

    I do appreciate your code suggestions and I am trying some new things. It appears to me that your code should be identical to the hit test I posted, except that it is a better way of codeing. I dont understand why putting this on the actuall hit clip on the 20 sector won't register with the scoreboard the same way the hit test I posted does....
    Code:
    onClipEvent (enterFrame) {
        for (i=1; i<3; i++) {
            if (this.hitTest(_root["dart"+i]["anim"+i]["hit"+i] == true)){
                _root.scoreboard.mark201.gotoAndStop("on");
            }
        }
    }
    I have written a couple very small and easy games.. tic tac toe,.. a vertical shooter, but seeing some of the things here makes me want to learn more, ... mario kart, some of the zelda games, 3d world engines and the like.Maybe this is a bit too ambitious of a project for me. I am experimenting with Electroserver also and it seems that even some very basic games done with some creativity are very fun to play online. Although, I am finding that creating a dart game is not as "basic" as I once thought.

    Thanks again for your code ideas, and making me feel dumber than dirt. The AI player, adding a two player option, allowing for dart upgrades to increase difficulty in the game, allowing for multiple dart games, connecting with Electroserver to allow real time two player games, and connecting to a mySQL database to store player info and more is a bit down the road....... too ambitious??? lol

    Thanks again
    ~GD~
    Operator Error

  11. #11
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    All the things your talking about are possible and would make for a fun little dart game - If I get a little time i'll try to code something up for you, but it sounds like your the kind of person who will figure it out, just keep at it - I am currently working on a fruit machine as a mini game for my RPG so I'm a little pressed!!

    RipX

  12. #12
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thanks for your suggestions! Trying to understand someone else's code is difficult for me. I really need to learn this stuff myself. Working with a scoreboard function now. Here is what I have come up with from yours and Marshall's code suggestions....
    Code:
        boardHit = function () { for (i=1; i<3; i++) {if (_root.board.hitTest(_root["dart"+i]["anim"+i]["hit"+i] == true)) {nextLight();}}};
        nextLight = function () { var j = 1;_root.scoreboard["mark"+(points)+j].gotoAndStop('on');j++;};
    Couple questions......
    1. Since all of the marks are named the same,.. mark201, mark202,mark203,mark191,mark192,...etc Should the nextLight function use that path....... _root.scorebaord.mark[points+j].gotoAndStop('on')
    So far, the only thing that will work for this function is if I use it like....
    Code:
     nextLight = function () { var j = 1;_root.scoreboard["mark20"+j].gotoAndStop('on');j++;};
    If I change the j variable, it will light the corresponding 20 mark light, but from the start of the movie, not on dart land.
    If I hit the 20 segment with a dart, "points" registers in the output text field correctly but the scoreboard does not register.

    2. Should I be including the "." in the code like this...

    Code:
      nextLight = function () { var j = 1;_root.scoreboard+"."+["mark"+(points)+j].gotoAndStop('on');j++;};
    3. Do I need to use both functions? It seems like I could power the scoreboard with just the nextLight function, if I can get the code worked out. It is coded on the first frame and I call the function at the end of the code. Also tried putting an onenterframe on the scoreboard to call nextLight().

    Thanks again for your time and suggestions.
    Regards
    ~GD~

    edit****
    Why wont the nextLight function work????????
    Code:
    scores = [0, 0, 15, 0, 17, 0, 19, 0, 16, 0, 0, 0, 0, 0, 0, 20, 0, 18, 0, 0];
    dists = [4, 11, 56, 62, 94, 102];
    offset = -(360/scores.length)/2;
    function land(dart) {
        if (dartNum>3) {
            newTurn();
        }
        dartNum++;
        var distx = int(dart.x)-_root.board._width/2;
        var disty = int(dart.y)-_root.board._width/2;
        var dist = Math.sqrt(distx*distx+disty*disty);
        var angle = Math.atan2(disty, distx)*180/Math.PI;
        if (dist<dists[0]) {
            // double bullseye
            points = 50;
        } else if (dist<dists[1]) {
            // bullseye
            points = 25;
        } else if (dist<dists[dists.length-1]) {
            if (angle-offset<0) {
                angle += 360;
            }
            var points = scores[Math.floor((angle-offset)/(360/scores.length))];
            if (dist>dists[2] && dist<dists[3]) {
                points *= 3;
            } else if (dist>dists[4] && dist<dists[5]) {
                points *= 2;
            }
        } else {
            points = 0;
        }
        totalScore += points;
        total = "Total: "+totalScore+" Points";
        output = points+" Points!";
    }
    function nextLight() {
        var j = 1;
        _root.scoreboard.mark[(points)(j)].gotoAndStop('on');
        j++;
    }
    function newTurn() {
        dartNum = 1;
        j = 1;
        totalScore = 0;
    }
    nextLight();
    newTurn();
    Last edited by grvdgr; 07-30-2003 at 04:45 PM.
    Operator Error

  13. #13
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Hi grvdgr,

    Still keeping at it i see, nice one. Glad that you're not giving up and are taking the opportunity to learn.

    Well, i read through this ( very long! ) thread. I'm still not sure what you want to get out of it in the end. I have a friend who plays for our local pub's darts team, so i'll get him to explain to me the rules of cricket more thoroughly i think! Going from your last post...

    "Why wont the nextLight function work????????"
    Well, i've never seen this syntax where you put () round things inside an array operator brackets []. What is "points"? I'll keep reading till i understand, but thought i should post to let you know i'm thinking about it...

    Could you explain a bit about what these lights are to show, so i understand, the link to your latest version perhaps? RipX seems to be a little busy, I'll try to take over from him I know he's a big time coder, and has lots of work. I'm no professional, but hopefully i can give you time.
    jonmack
    flash racer blog - advanced arcade racer development blog

  14. #14
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Hi Jonmack,
    I am obviously not a professional coder either. That becomes apparently clear in reading some of my rambling posts and sloppy code. I am learning a great deal. The dynamics of coding the concept and math of this game, I understand now after studying this for some time. I thought this was going to be an easy to intermediate project when I thought of it. I am finding it is much more dynamic than I thought it would be. The scoreboard is only one of many hurdles I see down the road on this. So, I am taking things one step at a time.

    The scoreboard is just the scoreing numbers (20 - 15) and the bullseye. Each number contains 3 MC's("lights"). The lights are just a two frame animation. Blank first, red dot in the second. Frame labels "off" and "on" respectively. This is the correct path to the 1st marklight on the 20.........
    _root.scoreboard.mark201.gotoAndStop ('on");

    I am trying to use the points variable in the code......
    var points = scores[Math.floor((angle-offset)/(360/scores.length))];
    and a varible to increase the 1,2,or 3.......
    Code:
    function nextLight() {
        var j = 1;
        _root.scoreboard[(points)+(j)].gotoAndStop('on');
        j++;
    I don't know how to arrange this to work dynamically. I thought that "points + j" would add the variables together, instead of listing them seperately. The code I posted was a trial to list the variables seperatly. I also see a problem of having the scoreboard determine what marks are lit and what marks need to be. If I hit a 15 and light up one mark, then a double 20 and light up 2 20 marks, how will I be able to determine that if I hit the 15 again, the second mark should light up?

    Here is a demo. Click a dart flight, drag it over the board, release to throw. Right now, I have the first mark20 light set to light up no matter what on mouse release, just to see how that should work.

    http://ntdesigns.net/downloads/darts5.swf
    http://ntdesigns.net/downloads/darts5.fla

    Thanks for looking
    Regards
    ~GD~
    Operator Error

  15. #15
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    I can't help thinking that this light method you want to use is a little strange and pointless, personally i'd just have the 501/503 and count them down! But simply your not calling the function anywhere, for a start functions shouldn't be inside other functions, they are simply called from the initial function!! :

    Code:
    ...................
    			points *= 3;
    		} else if (dist>dists[4] && dist<dists[5]) {
    			points *= 2;
    		}
    	} else {
    		points = 0;
    	}
    	totalScore += points;
    	total = "Total: "+totalScore+" Points";
    	output = points+" Points!";
            // Added this to call the nextLight() function!!
    	nextLight();
    }
    //
    // Moved these !!!
    newTurn = function () {
    	j = 1;
    	dartNum = 1;
    	totalScore = 0;
    };
    // set a global variable for this counter or it will always be 1!!
    _global.count20 = 1;
    // The function is called from the other function but should be outside the other!!!
    nextLight = function () {
    	_root.scoreboard["mark20"+count20].gotoAndStop('on');
    	count20 += 1;
    };
    newTurn();
    That works but I don't know where on earth your calling it to turn on somewhere else so it turns them all on and I don't know where - heheh

    RipX

  16. #16
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Hi grvdgr,

    Right, I have downloaded your file. Few things that puzzle me. Are the functions boardHit and nextLight being used yet? They are defined ( and in the wrong place too i think ), but then i can't see where else they are called except at the bottom. Becasue they are defined within another function, they are only seen within that function ( called variable scope ) so even the one reference to calling these 2 function won't work. ( Stick a few trace's inside each function, they never get called ).

    I have a few ideas on how to make this problem much more simpler, but I need to know one thing. Does it matter which order the lights are illuminated? I'm guesseing, from the look of it, not. In which case we can store them in, yep, you guessed it, another array! That way you can check which light has been activated already ( from: " how will I be able to determine that if I hit the 15 again, the second mark should light up?" ) Well this is how. If the order of the lights matters we just need a more complicated array.

    I'll leave it at this until, say, tomorrow ( i'm at GMT, so in about 12 hours from now-ish ), but see if you can think of what i'm suggesting. If we store the number of times each segment has been hit ( and therfore the number of lights to be shown ), in a list, like how we stored the values of each segment earlier, we can use that list later to look up each segment very easily. Have a think.

    Speak to you tomorrow.
    jonmack
    flash racer blog - advanced arcade racer development blog

  17. #17
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thanks for looking

    Ripx
    The light method is just a visual scoreboard and strictly for a "cricket" dart game. The main code works pretty well for a 501 or 301 game, just subtract the totalScore from 301 or 501. I think I even understand how to make those games double in or double out to play or win. Eventually, I would like to have 501, 301, cricket, and possibly a couple other dart games, ie.... strike out, baseball, ... there are lots of them, and have them all selectable through one interface. I tried putting the function in the main timeline to call it when the dart lands. I thought in order to do that, I would have to put the function nextLight inside the dart(land) function. My inexperience. I have also tried calling the nextLight function from the scoreboard MC in an onenterframe event.The one place I did not try the function is where you put it. Would that be the same as putting it before the dart(land) function, or does it have to be after the "points" variable to be able to use that variable?
    // set a global variable for this counter or it will always be 1!!
    _global.count20 = 1;
    Thanks for that suggestion! I will need that. Still not sure how to set that so it would work for all the numbers in the score array dynamically keeping track of each one. Could that be done with an array, something like this...
    _global.score.count = 20,19,18,17,16,15,bullseye;


    Functions are new to me. I had to look up in a couple of my books what you even meant by having a function inside another function. The version I posted is darts5. I have 4 others with different versions of my bad code attempts. It just seemed this one might be the easiest to understand.

    Jonmack
    The functions in the main timeline are my attempts at understanding functions and how to dynamically power the scoreboard based on the points variable. After researching a bit further, I think the boardHit function I have there is useless and can be removed. The nextLight function should be all that is needed to power the scoreboard. The lights on a regular dartboard light up from left to right for each number. I would like to keep it that way in the game. The marklights are named in a way to be able to increment them...... mark201, mark202, mark203, mark191, mark192, mark193.. etc.... I think you might have something with setting them in an array and tracking the hits on them that way. Wondering if this can be done with the existing "scores" array? By setting them up in an array like you suggest, it might be easier to add points on "closed" numbers also. Another facet of the game I have yet to incorporate.

    Thanks for the ideas!
    I have dart league tonight, so back at it tomorrow!
    Regards!
    ~GD~
    Last edited by grvdgr; 07-31-2003 at 06:47 PM.
    Operator Error

  18. #18
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Your making this very complicated for yourself, i know that when you get it in your head that you want to do something it's very easy to start trying to do the things without learning them first so i would seriously suggest learning how to make a nice tidy movie first - for example my movies rarely have anything on screen and are structured in a way to make things easy in the long run, for example, what is the 20-15 and bull for?? It's near impossible to give advice when you haven't explained the way your game will work!

    functions:

    Simply blocks of code seperated into managable pieces and activated when needed....
    Code:
    hello = function() {
     trace("hello world")
    }
    // activated with:
    hello()
    
    ---------
    
    helloLive = function(message) {
       trace(message)
    }
    // activated with:
    // Pass the info in the function
    helloLive("hello world")
    
    ---------
    
    var hello = "hello world";
    helloVar = function() {
       // trace the hello variable
       trace(hello)
    }
    // activated with:
    helloVar()
    Now for arrays cos your quite out!!
    Code:
    myArray = new Array()
    myArray = [20,19,18,17,16,15,'bullseye']
    itterArr = function() {
        for (var i=0; i<=myArray.length;i++) {
            trace(myArray[i])
        }
    }
    itterArr()
    Check syntax cos I typed straight into Flashkit!!

    RipX
    Last edited by RipX; 07-31-2003 at 09:32 PM.

  19. #19
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    I have read and reread the definitions of functions and arrays.I am trying to learn how to use and understand them in this project. I tested the hello world function in several ways as well as different array examples. One question regarding arrays. Which is a better way to write them. I have found there are two ways of declaring an array...
    Code:
    myScore = new Array(7);
    myScore[0] = 20;
    myScore[1] = 19;
    myScore[2] = 18;
    myScore[3] = 17;
    myScore[4] = 16;
    myScore[5] = 15;
    myScore[6] = bull;
    or simply....
    Code:
    scores = [0, 0, 15, 0, 17, 0, 19, 0, 16, 0, 0, 0, 0, 0, 0, 20, 0, 18, 0, 0];
    the second array is the scores array I use in the dart game. It is just the numbers around the board with the scoring numbers. The rest are set to 0.

    I play darts in a league, I might have mistakenly assumed that everyone knows what the cricket version of darts is. In short....
    Cricket Darts....
    The scoreing segments are 20,19,18,17,16,15,bullseye. You must hit 3 darts on each number to "close" the number. After a number is closed, if it is hit again, it adds the number to the point total. The only way to score points is on a closed number. To win a two player game, you must have all segments closed, plus have the highest point total.I am writing this as one player right now, just to see if I can get the mechanics of it down. Two player will be the eventual goal. The scoreboard is just a visual marker of how many times a segment has been hit. There will be a seperate textfield for the totalpoints scored. The scoreboard function is proving to be as interesting as the math behind the actual scoring. It needs to determine what segment to light, how many to light, if the segment is closed to score points, and eventually, if the other players segment is closed, to not allow points. ex, If I was playing you and I went first and hit a triple 20 and 2 single 5's. My 20 is closed. If you throw and hit one 20, a triple 18, and a single 1. That is one complete turn. My next turn, I have the option of closing another number, going for points on my closed 20, or trying to close my 18 to keep you from scoring points on that. If both players have a segment closed, no points can be scored on it.

    I hope this makes some sense. I think I have something to work with in Ripx's suggestion of setting a global j variable. I think this needs to be an array to control the lights. Something like j[1]=mark201,j[2]=mark202,j[3]=mark203,j[4]=mark191..... this way, you will have a separate j value for each light value. Still not sure how to set it up so it can tell if 1 single 20 is lit, that the next hit on the 20 should light the second light......
    _root.scoreboard.mark[points+j].gotoAndStop("on");

    I guess I need to work on shortening up my long winded posts some, sorry. Gonna see what I can come up with for a global light array.

    Regards
    ~GD~
    Last edited by grvdgr; 08-01-2003 at 09:40 AM.
    Operator Error

  20. #20
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by grvdgr
    One question regarding arrays. Which is a better way to write them. I have found there are two ways of declaring an array...
    Code:
    myScore = new Array(7);
    myScore[0] = 20;
    myScore[1] = 19;
    myScore[2] = 18;
    myScore[3] = 17;
    myScore[4] = 16;
    myScore[5] = 15;
    myScore[6] = bull;
    or simply....
    Code:
    scores = [0, 0, 15, 0, 17, 0, 19, 0, 16, 0, 0, 0, 0, 0, 0, 20, 0, 18, 0, 0];
    They do same thing, so you can use whichever you like better

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