PDA

View Full Version : frames problem in AI controlled enemy



AdamZZ
November 6th, 2006, 11:29 AM
i need help with my code i have some simple AI but the enemy controlled by it isnt working :S instead of playing the frames it stops :S look at my code and help me please.

its a KH2 platform game using sora in final form.



onClipEvent (load) {
dead = false
_root.varduskhp = 1001;
}
onClipEvent (enterFrame) {
speed = 4;
if(_root.finalsora._x > this._x && !dead) {
left = 0;
_x += speed;
} if(_root.finalsora._x < this._x && !dead) {
left = 1;
_x -= speed;
}
if(left==0){
gotoAndPlay(6);
}else{
gotoAndPlay(3);
}

Holmesc
November 6th, 2006, 06:39 PM
Well, first of all, you need to have one more closing bracket at the end. Second, do you know about 'else if'? Instead of using this code:

if(_root.finalsora._x > this._x && !dead) {
left = 0;
_x += speed;
} if(_root.finalsora._x < this._x && !dead) {
left = 1;
_x -= speed;
}
if(left==0){
gotoAndPlay(6);
}else{
gotoAndPlay(3);
}

Use this code:

if(_root.finalsora._x > this._x && !dead) {
left = 0;
_x += speed;
} else if (_root.finalsora._x < this._x && !dead) {
left = 1;
_x -= speed;
} else if (left==0) {
gotoAndPlay(6);
} else {
gotoAndPlay(3);
}
}
In the second code, I also took the liberty of adding some spaces that go with proper syntax. If what I gave you doesn't work, try to post the .fla file.

habes
November 7th, 2006, 12:44 AM
i think whats happening is gotoAndPlay(6) keeps happening over and over. He keeps going to frame 6, and doesnt get a chance to play. you could put in variable so it doesnt repeat or something, im not sure how your games set up.