|
metadata
I have a problem with the hitTest when it tries to change an array variable it changes them all and it only works for one of the attached MCs.
Please, Please help?
|
|
|
metadata
Um… can you please be a little more ambiguous?
|
|
|
metadata
|
|
|
metadata
No, I wasn’t offering to debug your file… I am trying to suggest that you provide the forum with a little more information about your problem. How do you expect anyone to be able to help you when your question is so ambiguous (if you don’t know what that means, it’s in the dictionary).
|
|
|
metadata
It’s exactly as I said insted of changing one part of an array it changes the whole array.
If it helps to know the code is in a movieclip and there is a loop to control the several attached movieclips.
Plus your use of ambiguous is very ambiguous. The phrase “less vague” would be better.
|
|
|
metadata
please post the code we cant really help you like this.
|
|
|
metadata
Heres the code:
`
onClipEvent (load) {
chavA = new Array();
chavb = new Array();
cnum = new Number();
}
onClipEvent (enterFrame) {
num--;
if (num<-9) {
num = 0;
mc = _root.attachMovie("chav", "chav"+num, cnum);
cnum++;
chavA.push({Name:mc, bob:0, scale:1, hp:2});
chavb.push(false);
}
for (i=chavA.length-1; i>-1; i--) {
chavA[i].Name._y -= chavA[i].bob;
if (chavb[i] == true) {
chavA[i].bob--;
chavA[i].Name._x += 5*chavA[i].scale;
chavA[i].Name.gotoAndStop(8);
}
if (chavA[i].bob == -10) {
chavA[i].bob = 0;
chavb[i] = false;
chavA[i].Name.gotoAndStop(1);
}
if (chavb[i] == false) {
if (this.wack.hitTest(chavA[i].Name)) {
chavA[i].scale = _root.scale;
chavA[i].bob = 9;
chavb[i] = true;
chavA[i].hp--;
}
}
if (chavb[i] == false) {
if (chavA[i].hp == 0) {
removeMovieClip(chavA[i].Name);
chavA.splice(i, 1);
}
xdis = _root.blob._x-chavA[i].Name._x;
if (xdis>0) {
if (xdis>3) {
xspeed = 3;
chavA[i].Name._xscale = 100;
} else {
xspeed = xdis;
}
} else {
if (xdis<-3) {
xspeed = -3;
chavA[i].Name._xscale = -100;
} else {
xspeed = xdis;
}
}
chavA[i].Name._x += xspeed;
ydis = _root.blob._y-chavA[i].Name._y;
if (ydis>0) {
if (ydis>3) {
yspeed = 3;
} else {
yspeed = ydis;
}
} else {
if (ydis<-3) {
yspeed = -3;
} else {
yspeed = ydis;
}
}
chavA[i].Name._y += yspeed;
if (xdis<40 && xdis>-40) {
chavA[i].Name.play();
}
}
}
if (this.hitTest(_root.chav.hit)) {
_root.hart.health._x--;
}
if (Key.isDown(Key.SPACE)) {
this.play();
}
if (Key.isDown(Key.LEFT)) {
this._x -= 10;
_root.scale = -1;
this._xscale = 100*_root.scale;
this.legs.play();
}
if (Key.isDown(Key.UP)) {
this._y -= 10;
this.legs.play();
}
if (Key.isDown(Key.DOWN)) {
this._y += 10;
this.legs.play();
}
if (Key.isDown(Key.RIGHT)) {
this._x += 10;
this.legs.play();
_root.scale = 1;
this._xscale = 100*_root.scale;
}
}
`
I think the mistake is in the loop.
Sorry about the varible names I name them after random people I know.
|
|
|
metadata
Please read the sticky regarding how to post code in the forums. If you post it like that, no one is likely to read it. I fixed it for you this time.
|
|
|
metadata
I think the mastake is:
`
chavA[i].Name.y = chavA[i].bob;
if (chavb[i] == true) {
chavA[i].bob-;
chavA[i].Name.x += 5*chavA[i].scale;
chavA[i].Name.gotoAndStop(8);
}
if (chavA[i].bob == 10) {
chavA[i].bob = 0;
chavb[i] = false;
chavA[i].Name.gotoAndStop(1);
}
if (chavb[i] == false) {
if (this.wack.hitTest(chavA[i].Name)) {
chavA[i].scale = _root.scale;
chavA[i].bob = 9;
chavb[i] = true;
chavA[i].hp-;
}
}
`
It allways seems to through them into the air so to speak and that it only works if you hit the first one attached.
For example if 2 are created and I defeat the first then and only then can i go after the second.
|
|
|
metadata
|
|
|
metadata
Ok, one problem is that you’re using cryptic variable names. Obviously, that’s not a good practice, because it will confuse anyone who tries to read your code. You should always give your variables appropriate names for what the variable actually represents, honestly I won’t even look at your code until that happens, because it’s just a really, really confusing thing to do. I mean, it’s no wonder you’re having problems when I see variables named “bob”… it’s just silly.
|
|
|
metadata
Its also bad to repeat chavA[i] over and over. You should save that to a local variable and use the variable instead.
|