A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: multiple hit tests in one line?

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

    When i said 12-ish hours, i meant 24

    Some suggestions. It may be easier to have one MC with 4 frames to represent each 3 lights per score. First frame blank, 2nd with 1 light, 3rd with 2, 4th with 3 lights. Cuts down on lots of MC names, bit more easier to know what is going on.

    2nd of all. Make a new array ( could encorporate it into the score array like you suggested, but for now I would keep it seperate until you are more comfortable with the code ) to store the number of times a certain segment has been hit.

    The point of functions is to make a re-usable chunk of code that can be used any time. Each function should so a specific task. Don't try to do too much in one function, break it up. This will be of benefit later on if you try to do multiple types of dart games within a single flash file. Making a function to report which segment of the board the dart landed on is useless if it contains game specific code - you would have to re-write it for every type of game. So you have got a function to find out which segment the current dart landed in. Use the result of that funtion to determine what you do with that knowledge ( ie in a game specific area of code ). In cricket it would be to add 1 to the number of times that segment has been hit, and if greater than 3 then a score is added. In 501 it would be to count down the dart score from the total score.

    I would enhance the function you call "land" - the one that calculates where a dart lands - to do the following: It would return an object, not just do something game specific. That returned object could be used in game specific functions to control how that game is played elsewhere. The object that is returned would have several properties. The score that the dart achieved ( double 10 = 20, bull = 50 ), the segment that is was in ( 20, bull ), and the type of segment ( double, bull, etc ). That way you have a generic function that can be used with all types of game. An advantage.

    That's all i can think of right now. Hope it is some help. Forgive me if it's a bit illegiable, i've been to my local pub tonight, but i haven't been played darts
    jonmack
    flash racer blog - advanced arcade racer development blog

  2. #22
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thank you for that suggestion! That makes things MUCH easier to manage. I reduced the scoreboard to one MC for each number. Each MC has 4 frames and reduces the naming method for the lights to....
    mark20,mark19,mark18,mark17,mark16,mark15,markbull .
    7 clips to refer to instead of 21 having the lights all as MC's.

    One of the skills that I do possess is the ability to make things much more complicated than they need to be. I can now manipulate each of the mark lights like this.......
    Code:
    nextLight = function () { _root.scoreboard.mark19.play();};
    The lights light up in order with the each dart land. However, they light up no matter where the dart lands. I dont think I need to even calculate how many lights are lit or anything else accept being able to use the points variable instead of the actual number, mark"19" and telling each clip to simply go to the next frame.
    Trying to use "points" to replace the 19 does not register the scoreboard, but when I trace points, it registers correctly in the output window and in the output textfield in the movie.
    Code:
    nextLight = function () { _root.scoreboard.mark+points.play();};
    
    nextLight = function () { _root.scoreboard.mark(points).play();};
    
    nextLight = function () { var points = scores[Math.floor((angle-offset)/(360/scores.length)); _root.scoreboard.mark+points.play();};
    How can I use the points variable in the nextLight function??

    Thanks

    ~GD~
    Operator Error

  3. #23
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    nextLight = function () { _root.scoreboard.mark[points].play();};

  4. #24
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    I have tried that also. That will not register with the scoreboard either. Here is the code I have now. The myLight array is not being used. It was an attempt to single out the scoring point values. Also, in using _root.scoreboard.mark20.play(); it sends the scoreboard light ahead one frame at a time. How would I stop it from reseting when it gets to the last frame in the light MC? Set a variable in the last frame of each light movie to "closed" and use an if statement to check?
    if _root.scoreboard.mark[points]== closed
    _root.scoreboard.mark[points].stop();
    else
    _root.scoreboard.mark[points].play();
    Code:
    myLights = ['mark20','mark19','mark18','mark17','mark16','mark15','markbull'];
    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) {
        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;
            _root.scoreboard.markbull.play();
        } else if (dist<dists[dists.length-1]) {
            if (angle-offset<0) {
                angle += 360;
            }
            var points = scores[Math.floor((angle-offset)/(360/scores.length))];
            trace(points);
            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!";
        nextLight();
    }
    newTurn = function () { dartNum = 1;totalScore = 0;};
    nextLight = function () { _root.scoreboard.mark[points].play();};
    Thanks to everyone that has looked at this long and winding thread and pointed out many of my coding errors.

    ~GD~
    Operator Error

  5. #25
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Almost right tonypa The entire MC name must be within the square brackets, with no fullstop before the [ bracket. Or you could pass it into the function. This is one thing that i mentioned earlier - of greate help when trying multiple darts games. Something like
    code:

    function nextLight(arg) {
    _root.scoreboard["mark" + arg].play();
    }


    if you pass "points" into this, it replaced "arg" then "mark"+arg gets converted into the MC name then scoreboard.MCname.play(), which is right syntactically (is that a word? )

    Have the dart landing function return an object... ( i'll skip most of the code, just to see how it's done really ):

    code:

    function land(dart) {
    r = {}; // new object to store returned variables

    ... // do all the normal calculations

    r.segment = segment; // save all the variables
    r.score = score;
    r.type = type // double, single, etc
    r.etc...

    return r;
    }



    Then you can, in a game specific function, store the results everytime a dart is thrown.

    code:

    lastDart = land(dart); // now lastDart has same properties as r object
    score -= lastDart.score // for example, in 501 etc
    nextLight(lastDart.segment); // to set a light in cricket...



    That way you can reuse land() with all your games, and use which properties of the r object that you need for a certain game. I know you maybe not used to objects, but it will help if you plan to do several games, and you'll have to learn about objects anyway, right!

    Digest that if you can See what you think.
    Last edited by jonmack; 08-02-2003 at 07:55 AM.
    jonmack
    flash racer blog - advanced arcade racer development blog

  6. #26
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by jonmack
    Almost right tonypa The entire MC name must be within the square brackets, with no fullstop before the [ bracket.
    bah, shame on me.

  7. #27
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Thanks again! I will study this. Once again, objects are new to me. I will need to research them some before it makes much sense to me. Not exactly sure what you mean by object, but I do see that listing the variables with each dart throw would be an advantage. With the code I have there now, to make it a 301 or 501 game, I would simply replace the "0"'s in the scores array to match the scores around the board, then subtract the total from 301 or 501. The dist variable determines double or triple on any segment. It will work fine for a countdown game without the scoreboard function I am attemting. Just subtract totalScore from 301 or 501. It does the math correctly for that.

    Thanks for the ideas!

    ~GD~
    Operator Error

  8. #28
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    ok, I have looked into the generic object. It is something I will absolutly need in advancing this to a two player game. The way I understand it, I would use this more for game data(storing variable information), than for the mechanics of the actual game.

    The mechanics of most any dart game is pretty much in the code I have. For example,if I want to change from a cricket game to a 301 or 501 game, all I need to do is adjust the scores array and subtract each dart hit from the game total. A high score game would be 10 rounds of adding each dart hit to totalScore.

    Where it gets interesting is when you have a game that tracks more than one hit on a segment(cricket, baseball, shang hi,etc)... Some of the variables that would be necessary in a two player game are not needed in a one player version.

    I am going to learn more about storing variables in an object. This will definitly be needed for two players. In the dart(land) function, can I store the variables from two players in one object, or create a seperate object for each player?

    The main thing I am having problems with right now is understanding how to use the points variable. I read your explanation....

    The entire MC name must be within the square brackets, with no fullstop before the [ bracket. Or you could pass it into the function. This is one thing that i mentioned earlier - of greate help when trying multiple darts games. Something like
    function nextLight(arg) {
    _root.scoreboard["mark" + arg].play();
    }
    I have tried that with the points variable set as the arg. I see that you can use the object to set the lights, but I don't understand that yet. I have added the object to the code, but more to research it than use it right now. I am puzzled why I cannot seem to get the scoreboard to react to the points variable. here is the code I have now.......
    Code:
    ...
    ...
    
            var points = scores[Math.floor((angle-offset)/(360/scores.length))];
            trace(points);
            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!";
        nextLight();
        // new object to store returned variables
        r = {};
        // save all the variables
        r.points = points;
        r.score = totalScore;
        // double, single, etc
        r.type = type;
        return r;
    }
    function newTurn() {
        dartNum = 1;
        totalScore = 0;
    }
    function nextLight(points) {
        _root.scoreboard["mark"+points].play();
    }
    If I use ......
    _root.scoreboard.mark20.play();

    or mark19, mark18, etc, the individual lights work.

    Also, how can I set the marks lights to react to a double or triple? Thinking out loud.... Set the frame label for two lights to double, three lights to triple for each light, then in the dist variable that determines double or triple....
    Code:
    if (dist>dists[2] && dist<dists[3]) {
                points *= 3;
          _root.scoreboard["mark}+points].gotoAndStop('triple');
            } else if (dist>dists[4] && dist<dists[5]) {
                points *= 2;
          _root.scoreboard["mark}+points].gotoAndStop('double');
    although, this doesn't allow for if a single mark is already lit when a double or triple is hit. I guess getting the scoreboard to work with individual hits is the main thing to get working for now.
    Thanks for your ideas!
    Any suggestions appreciated!

    Regards
    ~GD~

    edit*** Can I even use the variable "points" outside the dart(land) function if it is declared as a local variable to that function? Is this why I would need to create an object to hold that variable to use outside the function?
    Last edited by grvdgr; 08-02-2003 at 09:07 PM.
    Operator Error

  9. #29
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Hi gvrdgr,

    Well, you need a bit more knowledge of functions yet i see Don't worry, it'll all come together and make sense eventually.

    The variable points in your land function is only in that function. On that you were correct. You don't need to hold it in an object, you could just return it on it's own. But what an object can do is store several variables. You can only return a single thing from a function, so to return several you package them in an object, then split it up later back into the several variables.

    When you make a function that takes an argument you give a name to that argument in the function parethesis. I called it arg, you changed it to points. That is a completely different variable to the points in land(), and only exists in that function ( variable scope again ). What you haven't done is pass the points variable from the land() function into the nextLight() function. By putting points into the nextLight() function that is then the value of "arg". That then works out the right MC to light up. Have another look at RipX's reply about functions. See the second one? He has an argument ( called message ) and he put's whatever he wants in between () when he CALLS the function a line down.

    So that's why it won't work - you're not putting in the argument!

    Besides that, I would suggest again not to do anything in the land function other than return ( in an object ) the properties of the last dart to land. Then, IN A DIFFERENT FUNCTION, that is game type specific, call the nextLight() functions, and do anything else you need to do. Otherwise, you can't use land() for a 501 game for example. It would be trying to call a nextLight() function, which isn't needed in that game. Again, try to keep functions to one specific reusable chunk of code. Much easier to then expand it later.
    jonmack
    flash racer blog - advanced arcade racer development blog

  10. #30
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Jonmack,
    Thank you for your time and patience! I apologize for my inexperience. I have been trying to use the local points variable in the dart(land) function as a global variable to determine the scoreboard light to light up for the last three days.

    I have been practicing with very basic functions and arrays for a few weeks or so now. I am learning more. I understand what you mean now about calling the nextLight function inside the dart(land)function and the need to call it from a "game type specific" function. I am still a little fuzzy on how to pass information from one function to another, but I was stuck on using the local points variable as a global variable. Understanding that helps a great deal.

    Thanks again for ALL your suggestions! You have made me look at alot of this in a different way. Gonna go see if I can apply some of this. Thanks Yoda!

    Oh yea, I read your post on writing your own multi user server. Best of luck with that, pretty cool. I started looking into more advanced coding when I bought the book "FlashMX Creating Dynamic Applications" By Michael Grundvig and a few others. One of the things it comes with is Electroserver, a multi user server. I'm sure if your writing your own, you know of Electroserver. I have a couple of the books demo's online. I have been studying that some too with the intention of, one day, possibly using this dart game with Electroserver for the two person aspect of the game.

    Demos....
    http://ntdesigns.net/sea/battlship.swf
    http://ntdesigns.net/webtricity/AVATAR.swf

    my personal site, no one is usually there. I have it set up so you can use multiple browsers to sign in and test things, although there is a 5 person limit with the free version of Electroserver right now.

    Thanks again!
    Regards
    ~GD~
    Operator Error

  11. #31
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Originally posted by grvdgr
    Thanks Yoda!


    Function and the like arn't that hard, especially if you know a few languages. There's functions in most languages. Once you've done it for a while you won't think twice about how to solve a problem like this. Just keep at it.

    "Do or do not. There is no try."
    jonmack
    flash racer blog - advanced arcade racer development blog

  12. #32
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Duh! Totally forgot!

    That avatar thing is sweet. Had a go with a mate of mine, worked great. COuldn't get the battleship one, forbidden! I 'm aiming for something along the lines of that in my server. Still a long way to go! Only just learning java really. I know about ES of course, i might try it too, but i like the challenge of building something myself. It's just there is a suprising lack of server tutorials out there, or at least a quick google search, which normally are so great, finds nothing. I mean, there's plenty about servers, but not about multiple connection servers and how to communicate between clients. A chat program wouldn't be much good if you couldn't chat...
    jonmack
    flash racer blog - advanced arcade racer development blog

  13. #33
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    the battleship one is actually the more advance of the two links. It is very cool. A very organized and dynamic game design. The whole game is set up in about a paragraph of code and plays very well. The way it interacts with Electroserver seems very easy to manipulate for that or any other game. The main chat room would act as a gathering place for game challenges. I have studied some visual basic and have run across a few threads about creating a multi player web server. Might look in the VB forums for ideas on that. That is actually where I got the idea for this dart game. In the VB forums was a thread discussing that there are lots of 301 and 501 countdown type of dart games, but very few cricket or anything other than a countdown type of game. That link should work for the battleship game, if not, you can also get to it through the main entrance to the site. I have it set up as a members area to limit the number of people since I am only using the free liscensed version of Electroserver.

    http://ntdesigns.net/sea/battleship.swf

    or main site, go to the members area and create a username and password, but that link should work......
    http://ntdesigns.net

    Basically just an experimental area for me to play online, but I do build a few websites here and there through it for local businesses.

    I have the scoreboard working on dart land with the points variable now. Thanks again for your explanations! Still unsure how to call the function outside the dart (land) function, but understanding more as I go. I have a seperate "cricket" function I am working on calling the nextLight function from so I can eventually write a function for each game I use and only use the appropriate functions for the game being used. Learning more about the generic object as well. I had not planned on looking into the dynamics of storing variables for a two player game until I had the guts of a single player game working, but I see that is what I am going to need to store and reuse multiple variables. Thanks again for your time and suggestions. A great help!

    Regards
    ~GD~
    Operator Error

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

    Got that battleship one to work. Pretty cool, but how/what is connecting to server? Do you send back the score or something? ( if you do, don't look at mine it was poor! ) Logged in anyway, to see what it was like. Only had a quick look round though, still, i like the rooms and areas, nice touch.

    Well after my last post i went on an all out google frenzy to try and find some good tuts on multiplayer servers. Finally found one, but not had time to try it out on mine yet.

    Good to hear you're making some progress with it all. It will take some time to make all seperate functions for everything, but in the end it will be easier to make multiple games. Good luck with them all.
    jonmack
    flash racer blog - advanced arcade racer development blog

  15. #35
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    Hello again,
    The battleship game is turn based. The server handles transmitting the request for coordinates and graphics on both player boards and sending back data real time for game play. It works the same as the avatar chat, except that being turn based, you can use more graphics and not have to worry about speed as much. With multiple users, I think the avatar example, or any real multi player flash game would slow down considerably with around 10 or so simultaneous players. I have not had a chance to test that out yet.

    Back to darts!

    I have a couple more things to ask about. First, I am still having difficulty in calling the game functions outside of the dart (land) function. If I place them anywhere other than inside the dart (land) function, nothing works.If I place them individually inside the dart(land) function, they work. Functions I have for each game so far...

    Code:
    function countDown() {
        lastScore = _root.scoreboard.p1score;
        _root.scoreboard.p1score -= points;
        if (_root.scoreboard.p1score == 0) {
            _root.gotoAndStop("501win");
        } else if (_root.scoreboard.p1score<0) {
            _root.scoreboard.p1score = lastScore;
        }
    }
    Code:
    function countDown() {
        lastScore = _root.scoreboard.p1score;
        _root.scoreboard.p1score -= points;
        if (_root.scoreboard.p1score == 0) {
            _root.gotoAndStop("301win");
        } else if (_root.scoreboard.p1score<0) {
            _root.scoreboard.p1score = lastScore;
        }
    }
    Code:
    function highScore() {
        _root.scoreboard.p1score += points;
        if (_root.scoreboard.round == '10' && dartNum == 6) {
            _root.gotoAndPlay("hswin");
        }
    }
    not sure why, I have a dartNum++ in the dart(land) function. When I trace that, each dart registers two numbers, dart 1... 1, 2, dart 2.... 3, 4, dart 3...... 5,6. That is why the if statement uses dartNum=6, it works out to the third dart, not sure why this is happening.
    Code:
    function cricket() {
        if (_root.scoreboard["mark"+points] == closed) {
            _root.scoreboard.stop();
            _root.scoreboard.p1score += points;
        } else {
            _root.scoreboard["mark"+points].play();
        }
    }
    Would using the variables locally in the dart(land) function, ie... dist, distx, angle, allow me to use the points variable globally or would all the variables in that function need to be global in order to use the points variable in that way?

    Also, haveing questions about the way I am coding the scoreboard for cricket. I have it powered so that it works on individual marks, but the double and triple segments leave me confused with how to light up the scoreboard. ex.. If one mark is closed on 20 and you hit a triple 20, how to light up the two remaining marks and score 20 points is something I can't seem to grasp. I get it in my head that it should be done differently than the way I am coding it. Thinking out loud....
    if I hit 3 single 20's, I could use points divided by darts and get a factor of 3 to turn on 3 single 20 lights. If I scored a two single 20's and a triple 20, 100 points, points divided by darts wont work. The same if I hit 2 single 20's and a single 17. I need to somehow set a factor of 1, 2, or 3 for the dart lights, then something to determine closed marks and add points accordingly.

    I put it all together in one interface to help me understand some things. I can't seem to code it all in one frame and get the seperate functions to work appropriately, so I have seperated each game with scene's for now, until I understand how to code it more dynamically and only call the function to be used when needed.....

    Demo.... a few bugs here and there.Doubles and triples wont light the cricket scoreboard, singles will, except for the bull. No graphics for the actual game yet, just a pretty black screen.
    Darts Demo

    Any suggestions appreciated!
    Regards
    ~GD~
    edit*** can an object hold an array?.... if I put an array of myLights=mark20,mark19,mark18,etc.....markbull. Could I increment that by 1 each hit, or even two or three....."mark"+points...myLight[1]+1, else, myLight[1]+2,.... then determine if myLight[1]=3, p1score+=points? something like that, but more organized?
    Last edited by grvdgr; 08-07-2003 at 02:39 PM.
    Operator Error

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

    Why have you got 2 functions called countDown() ? Each variable/function/object etc must have a unique name. This could cause real problems when hunting down a bug

    OK, about the cricket lights. I'm assuming you've done my object returned from land(). Well, one of the things that can be returned in that object is the type of segment the dart landed in. Just use that in the cricket function to determine how many lights should get lit.

    Some psuedo code...

    Code:
    on dart thrown {
      dart = land(); // r object
      if dart.type == "single", dart.segment.lights += 1,
      if dart.type == "double", dart.segment.lights += 2,
      etc...
    }
    I.e., when a dart is thrown, use the returned objects "segment" to find which segment was hit, so you can know which light should change. Then use "type" to find out if it was a single, double etc so you know how many lights to add. Don't forget some kind of check to see if it's gone over 3, and cap it off at 3. And "open" that segment or whatever you need to do in cricket. Do you have to go in order? 20, 19. 18 etc? Then you could open that segment and allow the next one to be scored on, if that's how it works.

    "Would using the variables locally in the dart(land) function, ie... dist, distx, angle, allow me to use the points variable globally or would all the variables in that function need to be global in order to use the points variable in that way?"
    You don't need to know distx etc outside of land(), don't bother making them all global. Anything that you need outside of land, you put into the object that is return, and seperate it from that later.

    " can an object hold an array?"
    Of course. An object is just a bundle for other types of data, strings, arrays of strings, or numbers etc. Anything. Objects can be inside other objects too.

    Anyway. It's looking really good so far, i like it alot. Some suggestions? When all the main part is done, think about making it a bit harder to aim. Once you know the spot just above triple 18 which makes the dart land on triple 20, it gets a bit easy My friend who plays in my local pub's darts team that i told you about before sent me a link to a great dart game on miniclip.com. If you haven't seen it before take a look and maybe get some ideas. Here: http://www.miniclip.com/darts/darts.htm

    Keep up the good work.
    jonmack
    flash racer blog - advanced arcade racer development blog

  17. #37
    Infinite Loop grvdgr's Avatar
    Join Date
    Feb 2001
    Posts
    610
    That is a cool dart link.

    I have the idea of adding customizable characters once I get things a bit more functional. I have also been studying Jessica Spiegel's book "Application Design and Development". She has a game called "tag" that allows for the user to cusomize a character, ie, .. hair color, style, clothes color, style, ethnicity,and a couple other characteristics that would allow a player to not only customize, but reuse the character they create. I had the idea of using this with the avatar chat I have now to allow for multi person interaction and as the main game challenge room. Still undecided how to go about the organization of it all. As far as the difficulty, I have a few ideas for that. The leading one being using math.random to move the actual "hit" clip inside each dart animation and allow for different "sets" of darts, each set upgrading the math.random to a smaller area. The current set being the top set of darts. A one player game would allow for earned points and dart upgrades. Also had the idea of adding levels for each player, similar to the post board titles under you name. Beginner or guest...... "chicken wing", ......pro or signed up member.... "Zues Lightning Bolt Thrower", etc..... Lots of ideas for the customization of all this once I get things more in order.

    One thing I cannot understand is how to call the main game function outside of the dart(land) function. No matter what game I have tried, or where I have tried calling it, the function will not work unless I call it inside the dart(land) function. Any suggestions or obvious code mistakes I am making there?

    For the cricket scoreboard, how do I use the 1, 2, or 3 factor number to set the lights AND calculate points? I can manipulate the scoreboard now with "mark" + points, but that does not allow for a mark being closed and a triple landing. I am still experimenting with using the generic object to save variables but I can't seem to grasp the concept of what variables to store in "r" and how to retrieve and use them. Any suggested reading or code examples for this? The AS dictionary seems a bit vague when trying to apply my specific project to useing the object to store and retrieve dynamic variables for the scoreboard.

    ~GD~
    edit***
    The two functions called "countdown" are on the first frame of seperate scenes, until I can figure out how to call the functions dynamically and independently from the first scene. Actually, the code for each game is almost identical, except for the game function, but I cant figure out how to call it outside the dart (land) function, so every game is a different scene, right now
    Last edited by grvdgr; 08-07-2003 at 10:22 PM.
    Operator Error

  18. #38
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Hi,

    That avatar customisation on the chat sounds great! I can also answer 2 of your questions with one stone then. First, think of a way to save the avatar options, hair colour, skin colour, etc for a person? Wouldn't it be nice to bundle them all up together to describe that person? Yep, it's the good old generic object again. I'll show you a bit of code on how to do that, and hopefully aid your understanding of how abject can be used.

    So, first we make an empty object, ready for all the attributes. There's 2 ways.

    code:

    var person = new Object();
    var person = {};



    Now let's store some variables.

    code:

    person.hair.colour = "brown";
    person.hair.length = "short";
    person.eyes = "blue";
    person.top.type = "tshirt";
    person.top.colour = "white";
    // etc...



    So here, "hair" and "top" are themselves objects within our person object. The hair object has attributes colour and length, to descibe it. The top object has a type, in this case tshirt, and a colour. The eyes are just a simple attribute of the person object.

    If we then later wanted to know what colour hair this person had, we just go down the list of variables, using dot syntax..

    code:

    var personHairColour = person.hair.colour;



    It's just like the folder system on your computer, only instead of dots, it'll be \ ( something different on macs, : or something ) And each "object" is a folder. To get to something just go along the folder names. The last one in the list is like the file that you want to read. That's a very simple way of using objects. If you get really cocky you can make classes ( a blank generic template ) descibing a persons attributes, but without values, and fill them in later. That's full OOP! But maybe just stick to the simple usage for the moment though So you should be able to usse the same method to retrieve the different parts of the r object returned from land(). But remember to set the returned object into another variable. r won't exist ourside land(), so you can't just use r.segment, you set it to a new varialbe, newr, something like this...

    code:

    var newr = land(); // now newr has the properties of r
    newr.segment // is the same as r.segment
    newr.score // r.score
    // etc...



    As for the functions not working unless they are called in land(), then i don't know. You did change them so they are out of that function, right? ( sorry, i know we've been through this, but just wanted to make sure ) If you want ( and it's not to big ) you could send me your fla, or just copy the code at least and send that.

    ikissmonkey at hotmail dot com

    I'll be happy to skim over it and see why.

    I like the ideas for the darts game too. Will it be like, if you win against the computer you get more points, can buy better darts etc? That would be cool. This is going to be the best darts game out there at this rate!
    jonmack
    flash racer blog - advanced arcade racer development blog

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