View Full Version : True/ False statment problem
jose3760
February 5th, 2007, 12:06 PM
I have it where i have a little ball, and i push crates along. Im trying ot make it so that when then then crate goes into water, i cant push it anymore.
here is the code i have on the ball:
// This is the true/salse statement for the crate
onClipEvent(load){
crate = true;
}
//this moves our character (named ball)
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 21.15;
//this is to check if my crate is in the water or not
//if its not, then i can push it
//if it is in the water, then i shouldnt be able to push it
if (crate == true){
if (this.hitTest(_root.box)) {
_root.box._y -= 21.15;
}
// this is what it does if the crate(box) is hitting the water
} else{
_root.crate.gotoAndStop(2);
}
}
}
the rest is all the same, just changed for the different directions that your character will move, so i took it out
ok, now the code i have on the floor (not the water)
onClipEvent(enterFrame){
if(_root.box.hitTest(this)){
//this keeps the box normal
_root.box.gotoAndStop(1);
} else
// if the box isnt hitting the floor, go to the box's second frame, and make create = false
_root.box.gotoAndStop(2);
crate == false;
}
make sense?
if theres something u dont understand, or left out, just ask:s:
SacrificialLamb
February 5th, 2007, 04:38 PM
not entirely, what do you want? what is not happening? Or are you just showing off code that work's?
I would think the code at the to[ should have a "crate = false" bit as will and the code at the bottom is missing a "{" (may be 2) and the "crate == false" should be "crate = false" (with one "=") and in the notes at the top you have "true/salse" that most likely should be "true/false"
Nich
February 5th, 2007, 05:06 PM
The problem is that "crate" isn't in the same scope in each code. There are two crates in your code, floor -> crate and ball -> crate. In this example, your making floor -> crate = false, and expecting ball -> crate to be the same. It won't be.
If you want to access ball -> crate from your floor movie clip, use "_root.ball.crate = false", replacing ball with whatever your ball is called.
Hopefully that helps :).
jose3760
February 5th, 2007, 11:04 PM
ok.. hmm, how do I put it better.
I have the character (instance name of 'ball'), 3 boxes (instance names of box1, box2, and box3), and the ground.
what im trying to do is that my character can push the boxes along the ground, but when it moves off the ground, I cant push it anymore.
First ill show ALL of the code thats on the -->BALL<-- movieclip
onClipEvent (load) {
crate = true;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 21.15;
if (crate == true) {
if (this.hitTest(_root.box)) {
_root.box._y -= 21.15;
}
if (this.hitTest(_root.box1)) {
_root.box1._y -= 21.15;
}
if (this.hitTest(_root.box2)) {
_root.box2._y -= 21.15;
}
} else {
_root.box.gotoAndStop(2);
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(key.DOWN)) {
this._y += 21.15;
if (crate==true) {
if (this.hitTest(_root.box)) {
_root.box._y += 21.15;
}
if (this.hitTest(_root.box1)) {
_root.box1._y += 21.15;
}
if (this.hitTest(_root.box2)) {
_root.box2._y += 21.15;
}
} else {
_root.box.gotoAndStop(2);
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x -= 22;
if (crate==true) {
if (this.hitTest(_root.box)) {
_root.box._x -= 22;
}
if (this.hitTest(_root.box1)) {
_root.box1._x -= 22;
}
if (this.hitTest(_root.box2)) {
_root.box2._x -= 22;
}
} else {
_root.box.gotoAndStop(2);
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+22;
if (crate==true) {
if (this.hitTest(_root.box)) {
_root.box._x += 22;
}
if (this.hitTest(_root.box1)) {
_root.box1._x += 22;
}
if (this.hitTest(_root.box2)) {
_root.box2._x += 22;
}
} else {
_root.box.gotoAndStop(2);
}
}
}
ok, now the code on the -->FLOOR<-- movie clip
onClipEvent(enterFrame){
if(_root.box.hitTest(this)){
_root.box.gotoAndStop(1);
} else
_root.box.gotoAndStop(2);
crate == false;
}
onClipEvent(enterFrame){
if(_root.box1.hitTest(this)){
_root.box1.gotoAndStop(1);
} else
_root.box1.gotoAndStop(2);
crate == false;
}
onClipEvent(enterFrame){
if(_root.box2.hitTest(this)){
_root.box2.gotoAndStop(1);
} else
_root.box2.gotoAndStop(2);
crate == false;
}
i can move the boxes around, but when it moves off the ground i can still move them, whicch is a bad thing.
SacrificialLamb
February 5th, 2007, 11:47 PM
Nich was right. The var crate you are miss treating and I think the if statement is in the wrong place anyway.
The var crate on the FLOOR and on the BALL will named the same and you may think they are the same they are not var's are locale unless you tell them no to be, not to mention that when you use crate == false; (still worn after I told you it should be one "=") has no link to what box is now not able to be moved.
You might want to think about posting a fla.
jose3760
February 7th, 2007, 12:08 PM
i can post the .fla if you want, but its to big so ill make a small one
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.