|
-
racing game help
i have started to construct a racing game. i have the basic components, but i cant get it to that when u complete the 3 laps if goes to a new scene or frame stating that u won.
the coding for the lap counter looks like this:
onClipEvent (enterFrame) {
if (this.hitTest(_root.car) && once != 1) {
_root.lap++;
once = 1;
}
if (!this.hitTest(_root.car) && once == 1) {
once = 0;
}
}
Last edited by masked D; 05-19-2006 at 01:30 PM.
-
and i tried to to add an if statement that looked like this:
if(lap == totalLaps){
gotoAndPlay("Scene 2", 1);
}
-
Hey Timmy!!!
Howdy, do the last piece of code you posted with the first post code? Have you tried putting a _root. before the gotoAndPlay().?
-
yes i have. i have also tried _root. before the lap and the totalLaps but i dont think that would help. and i ahve tried lap = 3 and lap == 3 as in:
if(lap = 3) or if(lap==3)
-
First off, I wanted to help clarify your code a bit - maybe it might help you in figuring out the right AS for the game..
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.car) && once != 1) {
_root.lap++;
once = 1;
}
if (!this.hitTest(_root.car) && once == 1) {
once = 0;
}
}
It looks like you're checking based on a few things at once here, which might be messing things up - In the first if:
Code:
if (this.hitTest(_root.car) && once != 1) {
_root.lap++;
once = 1;
}
You look to see if (this) movie clip intersects the car movie clip, AND the variable once is NOT set to 1, and if so, you increment the lap counter and set once to 1. This seems fine - but next,
Code:
if (!this.hitTest(_root.car) && once == 1) {
once = 0;
}
You now look to see if (this) movie clip does NOT intersect the car movie clip, AND the variable once IS set to 1, so you've kind of got 2 different things here, A) does (this) intersect the car, and B) is once set to 1. This may be exactly what you want, but I think you may want to construct it differently. In the second code block, you check for
However, if the first if() is true, once gets set to 1 there, and then the second if() executes and checks for once = 1 there, in which case once is always 1. So you may need to use an else if() and re-structure your conditional tests a bit to get what you want here.
You also mentioned
i ahve tried lap = 3 and lap == 3 as in:
If you're doing a conditional checking here, you need if(lap == 3), as you need 2 ='s signs for comparison (1 for assignment).
It seems like
Code:
if(lap == totalLaps){
gotoAndPlay("Scene 2", 1);
}
would be what you want.. are lap and totalLaps variables in the same scope within your timeline? If you want, post your .fla and I'll take a look at it. Hope this helps
-
ok well i have tried it with 2 == so i i kno that doesnt work. if this particular method of doing the check point system was the only i could get it to work right now. ill post the fla for u tho. maybe u kno a better way to set it up. if u can do the lap system with checkpoints that would be awesome as well.
ubitos rally
-
Well, I fixed the problem - I think you were trying to compare a number variable and a string var from a dynamic textbox, which wasn't quite right - I fixed the .fla, but due to being at work right now I don't have access to a server to post it, could I email it to you?
-
yea email it to me at [email protected] or my aim is boydefecto if that works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|