Join 307,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,612 people online right now. Registration is fast and FREE... Join Now!
First of all, I don't think you want to use onEnterFrame. That executes the function you define once every frame at the framerate of your movie until you stop it again. I also suggest not using the var facility of you text box. Instead, give it the instance name of scorecounter. Now put this code on frame 1:
as
var score = 0; scorecounter.text = score;
function updateScore() { scorecounter.text = ++score; }
What is going on here is that you create the variable score, set it to 0 and make your textbox display that value. The function, when called, will update the text in scorecounter with an incremented score (putting the ++ first makes the increment happen before the update). I find using the text property of a text field to be a lot more reliable than the var.
Then on each frame that you want to increase the score you simply do this:
In the beginning the code didn`t work, but thanks to your explanation about the use of the onEnterFrame function, I called my functions instead and boom then the counter worked. However I still have some problems concerning the counter. You see I think the problem is that I still have an onEnterFrame function on frame 1 saying: onEnterFrame = function() { raw = Math.random(); times6 = raw * 6; die = Math.ceil(times6); if(die == 4) { gotoAndStop(10);
} }
The reason I still have this onEnterFrame function is that I don`t know how to make this frame repeat again and again until the condition is true. A loop will time out maybe after 15 seconds, and in theori the condition could be false for 90 seconds, before I want it to move to the end screen. If I write this code instead and try to make it into a timeline loop: function chance() { raw = Math.random(); times6 = raw * 6; die = Math.ceil(times6); if(die == 4) { gotoAndStop(10); }else{ gotoAndPlay(1); } } chance();
then after less than a second ( each time)the movie goes to a another frame 40, 50, 60 or 70, and if I write: gotoAndStop(1)
on frame 40, 50, 60 or 70 then my movie goes crazy. Is it my onEnterFunction who mess up everything or what do I do wrong?
If you put your code in code tags ( ) it makes it a lot easier to read!
So anyway, I'm not sure I understand what you're trying to do, but what currently happens in the function version of your code is that if die doesn't equal 4, the playhead just carries on and doesn't execute the function again. I'm only guessing, but if you want to hold the playhead on frame one until die equals four you can do something like this:
as
//halt the playhead stop();
//execute the following code //until the while condition is met. do { die = Math.ceil(Math.random() * 6); //output the value of die trace(die); } while (die != 4)
//executes when the loop is finished //and die equals 4 gotoAndStop(10);
A loop like this will execute very quickly though, so if you are wanting to create a delay, you can use setInterval to create a loop that executes more slowly. This example will check if die equals 4 once every half second:
as
//halt the playhead stop();
//prepare the function function chance() { die = Math.ceil(Math.random() * 6); trace(die); if(die == 4) { //stop the loop by clearing the interval //when die equals 4 clearInterval(intID); gotoAndStop(10); } }
//create an interval calling chance() every 500 milliseconds var intID = setInterval(this, "chance", 500);
Finally, you could use onEnterFrame if you want the loop to execute at the actual frame rate of your movie, but make sure you clear it when you have finished with it:
as
//halt the playhead stop();
//prepare the function function check() { die = Math.ceil(Math.random() * 6); trace(die); if(die == 4) { //clear the onEnterFrame when die equals 4 this.onEnterFrame = null; gotoAndStop(10); } }
//Create an onEnterFrame and assign it //to the check function this.onEnterFrame = check;
Like I say though, I'm only guessing about what you're trying to achieve. If this doesn't help you out could you explain a bit more about what you are trying to create?
This post has been edited by thehat: 22 Mar, 2008 - 05:44 PM
Sorry about the code tags, I am very new to this forum, so I wasn`t aware of it, but will remember it next time!
I appreciate your help very much, but something in the code I already have written down is messing up everything in my movie incl. your code, I just don`t know what it is. The thing I want to do is to make a simulation of a soccer match based on variables. Meaning Player A has 3 variables: midtfield, attack and defense the same goes with player B. if the number 4 is the random number on frame 1, then the movie will move on to frame 10, where a new random number will decide who gets the chance. If the chance goes to player A the movie will go to frame 20 and if player B gets the chance the movie goes to frame 30. If the movie is on frame 20 then a random number decides weather PlayerA scores or Not and the same goes on frame 30 for player B. then the movie either goes to a frame who shows a random movie clip where the player scores or misses. After that the process starts over until the timer reaches 90.
The problems I have left before my game is complete is to make the counter work, go back to frame 1 without messing up my movie and to play a random movie clip. I don`t know if you would be interested to see my code which basically consist of to find a random number and then if statements?
I think it will help if you post all you code so I can see where the conflicts are.
You might find it useful to not go back to frame 1 every time. Try using frame one to set up your 90 minute timer and to declare functions, then use a different frame as your return point after every goal attempt.
First of all, thanks for taken the time to help me
I tried to make a different return point after a goal attempt but without any luck, so I will try to post my game sofar. First give frame one the frame label "chance". Then make a dynamic field and put the number 0 into it and call it "mySeconds" in the var field. After that make a new dynamic field and place it like the other dynamic field on the "chance" frame. Call this field "scorecounter" in the instance place. Then make a keyframe on frame 10 and call it "tilhvem" another keyframe on frame 20 and call it "spillerA" another keyframe on frame 30 and call it "spillerB", another keyframe on frame 40 and call it "Ascorer", another keyframe on frame 50 and call it "Bscorer", another keyframe on frame 60 and call it "Amisses", another keyframe on frame 70 and call it "Bmisses", and make the last keyframe on frame 80 and don`t call it anything. Okay the stage has been set, so now the code. On the "chance" frame place this code:
CODE
stop(); var score = 0; scorecounter.text = score; function updateScore() { scorecounter.text = ++score; }
function wait() { mySeconds++; if (mySeconds == 91) { gotoAndStop(80); } } myTimer = setInterval(wait, 1000);
function chance() { raw = Math.random(); times6 = raw * 100; die = Math.ceil(times6); if(die == 4) { gotoAndStop("tilhvem"); }else{ gotoAndPlay("chance"); } } chance();
On the "tilhvem" frame place this code:
CODE
stop();
var playerA = 85; var playerB = 83; var total = playerA - playerB;
if (total == 0) { var playerAM1 = 1; var playerAM2 = 114; var playerBM1 = 115; var playerBM2 = 230; } else if (total > 0 && total <= 10) { var playerAM1 = 111; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 110; } else if (total > 10 && total <= 20) { var playerAM1 = 101; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 100; } else if (total > 20 && total <= 30) { var playerAM1 = 91; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 90; } else if (total > 30 && total <= 40) { var playerAM1 = 81; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 80; }else if (total > 40 && total <= 50) { var playerAM1 = 71; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 70; }else if (total > 50 && total <= 60) { var playerAM1 = 61; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 60; }else if (total > 60 && total <= 70) { var playerAM1 = 51; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 50; }else if (total > 70 && total <= 80) { var playerAM1 = 41; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 40; }else if (total > 80 && total <= 90) { var playerAM1 = 31; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 30; }else if (total > 90 && total <= 100) { var playerAM1 = 21; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 20; }else if (total > 100) { var playerAM1 = 11; var playerAM2 = 230; var playerBM1 = 1; var playerBM2 = 10; // Husk minus 10 er større end minus 90, hvis du satte et mindre end tegn der hvis "total" var minus 10 //ville "what" ikke blive vist fordi minus 10 er større end minus 90 }else if (total < 0 && total >= -10) { var playerAM1 = 1; var playerAM2 = 110; var playerBM1 = 111; var playerBM2 = 230; }else if (total < -10 && total >= -20) { var playerAM1 = 1; var playerAM2 = 100; var playerBM1 = 101; var playerBM2 = 230; }else if (total < -20 && total >= -30) { var playerAM1 = 1; var playerAM2 = 90; var playerBM1 = 91; var playerBM2 = 230; }else if (total < -30 && total >= -40) { var playerAM1 = 1; var playerAM2 = 80; var playerBM1 = 81; var playerBM2 = 230; }else if (total < -40 && total >= -50) { var playerAM1 = 1; var playerAM2 = 70; var playerBM1 = 71; var playerBM2 = 230; }else if (total < -50 && total >= -60) { var playerAM1 = 1; var playerAM2 = 60; var playerBM1 = 61; var playerBM2 = 230; }else if (total < -60 && total >= -70) { var playerAM1 = 1; var playerAM2 = 50; var playerBM1 = 51; var playerBM2 = 230; }else if (total < -70 && total >= -80) { var playerAM1 = 1; var playerAM2 = 40; var playerBM1 = 41; var playerBM2 = 230; }else if(total < -80 && total >= -90) { var playerAM1 = 1; var playerAM2 = 30; var playerBM1 = 31; var playerBM2 = 230; }else if(total < -90 && total >= - 100) { var playerAM1 = 1; var playerAM2 = 20; var playerBM1 = 21; var playerBM2 = 230; } else { var playerAM1 = 1; var playerAM2 = 10; var playerBM1 = 11; var playerBM2 = 230; }
function tilhvem() { raw = Math.random(); times6 = raw * 230; die = Math.ceil(times6); if(die >= playerAM1 && die <= playerAM2) { gotoAndStop("spillerA"); } if(die >= playerBM1 && die <= playerBM2) { gotoAndStop("spillerB"); } } tilhvem();
On the frame called "spillerA" place this code:
CODE
stop();
var playerAA = 84; var playerBF = 86; var total = playerAA - playerBF;
if (total == 0) { var playerAA1 = 1; var playerAA2 = 114; var playerBF1 = 115; var playerBF2 = 230; } else if (total > 0 && total <= 10) { var playerAA1 = 111; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 110; } else if (total > 10 && total <= 20) { var playerAA1 = 101; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 100; } else if (total > 20 && total <= 30) { var playerAA1 = 91; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 90; } else if (total > 30 && total <= 40) { var playerAA1 = 81; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 80; }else if (total > 40 && total <= 50) { var playerAA1 = 71; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 70; }else if (total > 50 && total <= 60) { var playerAA1 = 61; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 60; }else if (total > 60 && total <= 70) { var playerAA1 = 51; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 50; }else if (total > 70 && total <= 80) { var playerAA1 = 41; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 40; }else if (total > 80 && total <= 90) { var playerAA1 = 31; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 30; }else if (total > 90 && total <= 100) { var playerAA1 = 21; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 20; }else if (total > 100) { var playerAA1 = 11; var playerAA2 = 230; var playerBF1 = 1; var playerBF2 = 10; // Husk minus 10 er større end minus 90, hvis du satte et mindre end tegn der hvis "total" var minus 10 //ville "what" ikke blive vist fordi minus 10 er større end minus 90 }else if (total < 0 && total >= -10) { var playerAA1 = 1; var playerAA2 = 110; var playerBF1 = 111; var playerBF2 = 230; }else if (total < -10 && total >= -20) { var playerAA1 = 1; var playerAA2 = 100; var playerBF1 = 101; var playerBF2 = 230; }else if (total < -20 && total >= -30) { var playerAA1 = 1; var playerAA2 = 90; var playerBF1 = 91; var playerBF2 = 230; }else if (total < -30 && total >= -40) { var playerAA1 = 1; var playerAA2 = 80; var playerBF1 = 81; var playerBF2 = 230; }else if (total < -40 && total >= -50) { var playerAA1 = 1; var playerAA2 = 70; var playerBF1 = 71; var playerBF2 = 230; }else if (total < -50 && total >= -60) { var playerAA1 = 1; var playerAA2 = 60; var playerBF1 = 61; var playerBF2 = 230; }else if (total < -60 && total >= -70) { var playerAA1 = 1; var playerAA2 = 50; var playerBF1 = 51; var playerBF2 = 230; }else if (total < -70 && total >= -80) { var playerAA1 = 1; var playerAA2 = 40; var playerBF1 = 41; var playerBF2 = 230; }else if(total < -80 && total >= -90) { var playerAA1 = 1; var playerAA2 = 30; var playerBF1 = 31; var playerBF2 = 230; }else if(total < -90 && total >= - 100) { var playerAA1 = 1; var playerAA2 = 20; var playerBF1 = 21; var playerBF2 = 230; } else { var playerAA1 = 1; var playerAA2 = 10; var playerBF1 = 11; var playerBF2 = 230; }
function spillerA() { raw = Math.random(); times6 = raw * 230; die = Math.ceil(times6); if(die >= playerAA1 && die <= playerAA2) { gotoAndStop("Ascorer"); }else{ gotoAndStop("Amisses"); } } spillerA();
On the frame called "spillerB" place this code:
CODE
stop();
var playerAF = 87; var playerBA = 86; var total = playerAF - playerBA;
if (total == 0) { var playerAF1 = 1; var playerAF2 = 114; var playerBA1 = 115; var playerBA2 = 230; } else if (total > 0 && total <= 10) { var playerAF1 = 111; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 110; } else if (total > 10 && total <= 20) { var playerAF1 = 101; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 100; } else if (total > 20 && total <= 30) { var playerAF1 = 91; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 90; } else if (total > 30 && total <= 40) { var playerAF1 = 81; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 80; }else if (total > 40 && total <= 50) { var playerAF1 = 71; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 70; }else if (total > 50 && total <= 60) { var playerAF1 = 61; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 60; }else if (total > 60 && total <= 70) { var playerAF1 = 51; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 50; }else if (total > 70 && total <= 80) { var playerAF1 = 41; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 40; }else if (total > 80 && total <= 90) { var playerAF1 = 31; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 30; }else if (total > 90 && total <= 100) { var playerAF1 = 21; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 20; }else if (total > 100) { var playerAF1 = 11; var playerAF2 = 230; var playerBA1 = 1; var playerBA2 = 10; // Husk minus 10 er større end minus 90, hvis du satte et mindre end tegn der hvis "total" var minus 10 //ville "what" ikke blive vist fordi minus 10 er større end minus 90 }else if (total < 0 && total >= -10) { var playerAF1 = 1; var playerAF2 = 110; var playerBA1 = 111; var playerBA2 = 230; }else if (total < -10 && total >= -20) { var playerAF1 = 1; var playerAF2 = 100; var playerBA1 = 101; var playerBA2 = 230; }else if (total < -20 && total >= -30) { var playerAF1 = 1; var playerAF2 = 90; var playerBA1 = 91; var playerBA2 = 230; }else if (total < -30 && total >= -40) { var playerAF1 = 1; var playerAF2 = 80; var playerBA1 = 81; var playerBA2 = 230; }else if (total < -40 && total >= -50) { var playerAF1 = 1; var playerAF2 = 70; var playerBA1 = 71; var playerBA2 = 230; }else if (total < -50 && total >= -60) { var playerAF1 = 1; var playerAF2 = 60; var playerBA1 = 61; var playerBA2 = 230; }else if (total < -60 && total >= -70) { var playerAF1 = 1; var playerAF2 = 50; var playerBA1 = 51; var playerBA2 = 230; }else if (total < -70 && total >= -80) { var playerAF1 = 1; var playerAF2 = 40; var playerBA1 = 41; var playerBA2 = 230; }else if(total < -80 && total >= -90) { var playerAF1 = 1; var playerAF2 = 30; var playerBA1 = 31; var playerBA2 = 230; }else if(total < -90 && total >= - 100) { var playerAF1 = 1; var playerAF2 = 20; var playerBA1 = 21; var playerBA2 = 230; } else { var playerAF1 = 1; var playerAF2 = 10; var playerBA1 = 11; var playerBA2 = 230; }
function spillerB() { raw = Math.random(); times6 = raw * 230; die = Math.ceil(times6); if(die >= playerAF1 && die <= playerAF2) { gotoAndStop("Bmisses"); }else{ gotoAndStop("Bscorer"); } } spillerB();
On the frame called "Ascorer" place a circle on the stage and make it into a movieclip called ball and place this code on the frame and not the movieclip:
On the frame called "Bscorer" make another circle and make it into a movieclip and call it ball1 and place this code on the frame and not the movieclip:
On the frame called "Amisses" make another circle on the stage, make it into a movieclip and call it ball2 and write this code on the frame and not the movieclip:
There are a few points to make, I'll try and cover everything, and attach the file I've created at the bottom of this post if you want to check it out.
First of all, your timer. You have to set the mySeconds variable initially, otherwise the incremental operator in your wait() function won't work.
Next, the thing about the return point. I moved the 'chance' frame label to frame 2, and on frame to put a call to the chance() function. This ensures that the playhead never goes back to frame 1 and resets all the variables.
Back on frame one, I moved the creation of the interval and the call to chance into a function, and call that at the end of frame 1 instead:
as
function beginAgain() { myTimer = setInterval(wait, 1000); chance(); }
beginAgain();
Now you can call this function from any of your results frames to restart the game after a movieclip has played.
On to the results frames then, I made the onEnterFrame look like this (I'll only show one, they're all pretty much the same):
as
clearInterval(myTimer); stop(); updateScoreA(); trace ("PLAYER A SCORER");
ball.onEnterFrame = function() { //move the ball ball._x += 15; //if the ball is off the stage if(ball._x > Stage.width) { //clear the current onEnterFrame this.onEnterFrame = null; //restart the game _root.beginAgain(); } }
What happens here is that when the ball has moved off the stage the onEnterFrame is stopped and the game is restarted. You may have noticed the updateScore() function has become updateScoreA()? By having two add score functions and two score textfields you show both players scores separately. On frame 1 again:
as
scorecounterA.text = 0; scorecounterB.text = 0;
function updateScoreA() { scorecounterA.text = Number(scorecounterA.text) + 1; } function updateScoreB() { scorecounterB.text = Number(scorecounterB.text) + 1; }
So after all this you will notice that the timer still doesn't go up. This is because the game engine performs it's calculations in less than a second, and each results frame stops the timer, so the timer never gets incremented. If you remove the clearInterval from the misses frames, and change the call to beginAgain() to chance(), then your game works:
I don`t mind your meddling at all, without your help my game would be a disaster!
I tried to download your attached file, but when I try to open it, flash 8 give me a pop up message saying:
CODE
unexpected file format.
Do you know why, or is there another way you can sent the file to me? I think it will make it much easier for me to understand your explanations if I see them inside the movie you maked!
Sorry to write you another question, but I just noticed something in the movie! The frames "Ascorer", "Bscorer", "Amisses" and "Bmisses" are activated constantly, which means that the chance() function must be equal to 4 all the time, even if the code in frame 0ne is saying:
CODE
function chance() { raw = Math.random(); times6 = raw * 100; die = Math.ceil(times6); if(die == 4) { gotoAndStop("tilhvem"); }else{ gotoAndPlay("chance"); } }
And if I change it to this code:
CODE
function chance() { raw = Math.random(); times6 = raw * 4000; die = Math.ceil(times6); if(die == 4) { gotoAndStop("tilhvem"); }else{ gotoAndPlay("chance"); } }
then the chance() function is activated just as often? I mean that the random number should be number 4 each second out of 4000 numbers to choose from seems quite unlikely. Do you know how come this happens?
Well, a quick test with a trace before the if shows that the function only actually executes once. This is because the gotoAndPlay prevents code on that frame from executing a second time. Replacing the gotoAndPlay with another call to chance() causes the function to be called multiple times:
as
function chance() { raw = Math.random(); times6 = raw * 4000; die = Math.ceil(times6); trace(die); if(die == 4) { gotoAndStop("tilhvem"); }else{ chance(); } }
The problem you get now is that it is very likely that your function will execute more than 256 times without die equaling 4. Flash doesn't like that happening because it suspects you have created an infinite loop, and so it stops the operation to prevent a crash.
Why do you actually want to perform this random number generation? You aren't using the generated value anywhere, because it is always 4 when the playhead advances to 'tilhvem'. If you are trying to create a random delay then you should use setInterval with a randomly generated time. For the rest of this post, I'll assume that's what you're trying to do.
Delete the call to chance on frame 2, you won't be needing that, then replace the chance and beginAgain functions on frame 1 with these:
as
//return a number between 0 and 4000 function getDelay() { raw = Math.random(); times6 = raw * 4000; return Math.ceil(times6); }
//clear the game delay interval and start the game engine function proceed() { clearInterval(gameDelay); gotoAndStop('tilhvem'); }
//restart the game timer and set a new delay function beginAgain() { myTimer = setInterval(wait, 1000); gameDelay = setInterval(this,'proceed',getDelay()); }
Now you have a choice. If you want to go back to stopping the game timer when a miss happens, you can clear myTimer on the miss frames and change _root.chance() to _root.beginAgain. Otherwise, replace _root.chance() on both miss frames with this:
Well it wasn`t exactly what I had in mind. When I replace your new code with the old one, I get longer intervals between "Ascorer", "Bscorer", "Amisses" and "Bmisses" but it seems like they come at the same interval each time, meaning each 2 seconds or 4 seconds etc. depending how high I put the number in
CODE
raw * 4000;
It doesn`t seems like I get a random interval. Forinstens, the first time after 3 seconds the next time after 10 seconds etc.
The reason why I used equals to 4 is, that I want to make some code so it is unpredictable when one player gets a chance. Just like a soccer game, where there can be a chance after 4 minutes and then again after 10 minutes and so on, nobody never knows when it happens. If the chance() function in the flash movie is activated, then it will go to the frame I called "tilhvem" which in English means "to who" where a random number will decide if it is to player A or B. If it is to player A then it will go to the frame called "spillerA" meaning "playerA" in English, and if it is to PlayerB then the movie will go to the frame called "spillerB". On the frame called "spillerA" the random number will decide if player A scores or misses, and if the playhead is going to "spillerB" then a random number will decide if player B scores or misses. In both cases taken them to either the frame"Ascorer" or "Amisses (in the case that Player A gets the chance) or "Bscorer" or "Bmisses" (in case player B gets the chance). On those frames I want the timer to stop, while the movieclip is playing and begin again after the movieclip is gone. Then the movie goes back to the "chance" frame, where if the random number is 4, then the same process will happens until the timer reach 90.
My worries now is if you can do this in flash because I noticed too, that flash consider it as an unlimited loop.
I just thought I got the answer but no, it didn`t worked out
The thing I did was, that I changed the chance() function on frame 1 to this:
CODE
function chance() { raw = Math.random(); times6 = raw * 100; die = Math.ceil(times6); if(die == 4) { gotoAndStop("tilhvem"); }else{ chance1(); } }
and then I maked a new function called chance1 (in that way the function wouldn`t call on itself again and again) also on frame 1 in my movie looking like this:
CODE
function chance1() { raw = Math.random(); times6 = raw * 100; die = Math.ceil(times6); if(die == 4) { gotoAndStop("tilhvem"); }else{ chance(); } }
Unfortunately flash didn`t liked that either, but is there another way to make it work????
Simple answer is yes, but not with recursive functions. As you've seen, Flash gets upset easily, and this is a good thing because we don't want to overload the users machines. Let's go back to my previous post. If your only problem is that the interval seems very similar each time, then lets increase the possible amount of time. In fact, why not mess with the getDelay() function a bit so we can pass it a minimum and maximum amount of seconds to choose between?
Here is the new getDelay() function:
as
function getDelay(min:Number,max:Number) { //shameless copy from the help file! var randomNum = (Math.floor(Math.random() * (max - min + 1)) + min) * 1000; trace("Delay: "+randomNum); return andomNum; }
So now when you call getDelay() during the setting of an interval, you pass it a minimum and maximum number of seconds and it returns a value in milliseconds ready for setInterval to use. It will also write the delay to your output panel so you can assess whether the values need adjustment.
Your setIntervals should look like this:
as
//in the beginAgain function on frame 1: gameDelay = setInterval(this,'proceed',getDelay(1,5));
//on each of the missed frames: _root.gameDelay = setInterval(_root,'proceed',getDelay(1,5));
And here's the finished version, have fun footy_game.zip ( 14.37k )
Number of downloads: 24
This post has been edited by thehat: 25 Mar, 2008 - 12:10 PM