View Full Version : resseting a frame on collision
There is this mc and when the main player who you are comes in contact with it, I want the frame to reset. This is the code I have so far:
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1)
or this.hitTest(_root.player_2)) {
gotoAndPlay(2); }
}
the gotoAndPlay(2); wont work for some reason. Can you guys please help me out? Is there another code I should put in its place?
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1) || this.hitTest(_root.player_2)) {
gotoAndPlay(2);
}
}
Thats assuming the instance names are indeed player_1 and player_2
arkhan
06-02-2006, 05:19 AM
logical or in flash is ||
put a trace inside the if, to check if those hitTests are indeed returning true.
I think or works too because I tested it which a different function and or worked. But when you say add a string do you mean this:
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1)==true
|| this.hitTest(_root.player_2)==true) {
gotoAndPlay(2);
}
}
I bolded and underlined what I added. Thats what you ment by makin a true string right?
if it helps, here is the file that you guys can look at. Under the finish line(which you will know is the finish line)in the second frame, which is the second level, there is a square. That square has the code
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1)
|| this.hitTest(_root.player_2)) {
gotoAndPlay(2); }
in it. For some reason it wont go to frame 2. Its already on frame 2 so I just want the frame to reset sort of.
MaxManning
06-02-2006, 03:12 PM
In the fla you have here, the code doesn't match what you just posted.
This is what I see in the fla :
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1)==true
or this.hitTest(_root.player_2)==true) {
gotoAndPlay(2);
}
}
|| is the logical operator for OR as arkhan said already.
Freddy
06-02-2006, 07:07 PM
You guys understand that there is no point in adding the "== true" right?
Because you see,
if(object1.hitTest(object2)){
}
is exactly the same as
if(object1.hitTest(object2) == true){
}
The only difference is that the second one is longer. Thats it.
Do you ever have to write ==true
Freddy
06-02-2006, 07:43 PM
not in an if statement.
if you declare a variable you have to.
EX:
crazyCarl = true;
Then you call it...
if(crazyCarl){
trace("Carl's Nuts!!!");
}else{
trace("Carl's cool.");
}
MaxManning
06-02-2006, 08:16 PM
You don't really need to do it, but in examples I use it to make it very clear.
Not a major deal either way.
x = x + 1
or
x += 1
Same thing, one is a bit clearer to someone not familiar with programming.
arkhan
06-03-2006, 07:26 PM
I meant you should do this
[/code]
onClipEvent (enterFrame) {
if (this.hitTest(_root.player_1)){
trace("hit1");
}
if(this.hitTest(_root.player_2)) {
trace("hit2")
}
}
[/code]
if it doesnt trace anything, its because neighter hits occured..then you must look in your code what would be stopping these hitTests from hapening..and unless you post it we cant know..
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.