PDA

View Full Version : A small problem



Darkblade
March 18th, 2008, 11:21 AM
Hey everyone! I have been working on a SSBM style game and trying to get guns into the game... I have almost successed but every time my guy is pointing the right direction he shoots to the left. I know what the problem is, but I don't know how to fix it...

The code I need is like this :

if (_root.halo(right=true)) {
speed = -13;
} else if (_root.halo(right=false)) {
speed = 13;
}How do you make a MC look into a different MC for a variable? In this case the variable it needs is right = true;

Can anyone help me? Thanks in advance!

Darkblade

bluemagica
March 18th, 2008, 01:02 PM
not () but a dot '.' is what you should use....

if(_root.halo.right==true)
{
//do something
}

Darkblade
March 18th, 2008, 01:30 PM
not () but a dot '.' is what you should use....

if(_root.halo.right==true)
{
//do something
}

It still doesn't work... What am I doing wrong?


onClipEvent (load) {
//PLAYER PARAMS
speed = 13;
damageMin = 1;
damageMax = 5;
//INIT
hit = false;
xSpeed = speed+10;
ySpeed = speed-(random(5)+11);
_root.shot_mc.hit = true;
_root.shot_mc._visible = false;
hitFunc = function () {
_y -= ySpeed;
_x += xSpeed;
this.gotoAndPlay("hit");
hit = true;
};
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(this._x, this._y, true)) {
hitFunc();
} else if (this.hitTest(_root["falcon"])) {
//if its hit an enemy
hitFunc();
//execute hit function(see above)
_root.hp -= damageMin+random(damageMax-damageMin);
//damage enemy
break;
}
if (!hit) {
_y -= ySpeed;
_x += xSpeed;
}
if (_root.halo.right == true) {
speed = -13;
} else if (_root.halo.right == false) {
speed = 13;
}
}


On my Halo MC the code goes:

onClipEvent (load) {
health = 100;
fight = false;
crouching = false;
jumping = false;
dead = false;
jump = 0;
shotMax = 10;
shotCount = 0;
right = true;
}
onClipEvent (enterFrame) {
if (!dead) {
if (fight == false) {
if (crouching == false) {
if (jumping == false) {
if (Key.isDown(Key.LEFT) && fight != true) {
this._x -= 9;
this._xscale = -100;
this.gotoAndStop("run");
right = false;
} else if (Key.isDown(Key.RIGHT) && fight != true) {
this._x += 9;
this._xscale = 100;
this.gotoAndStop("run");
right = true;
} else {
this.gotoAndStop("idle");
}
}
}
}

I have more code but it is irrelevant for this problem...

ajcates
March 18th, 2008, 02:06 PM
Try sticking in trace functions along your code to see where it is messing up. Maybe the bullet code isn't receiving the right variable. Also if the character is sitting in idle, what way is he facing?

ArmoredSandwich
March 18th, 2008, 02:23 PM
Try sticking in trace functions along your code to see where it is messing up. Maybe the bullet code isn't receiving the right variable. Also if the character is sitting in idle, what way is he facing?

What do you expect to happen? You don't USE the 'speed' variable anywhere. It makes sense that nothing's happening.

Darkblade
March 18th, 2008, 02:32 PM
oh gosh... The bullets move and everything works fine, its only when my player faces the "left" direction he still shoots on the "right" direction. That is the problem. :(

BTW at the start he faces the "right".

ArmoredSandwich
March 18th, 2008, 03:20 PM
oh gosh... The bullets move and everything works fine, its only when my player faces the "left" direction he still shoots on the "right" direction. That is the problem. :(

BTW at the start he faces the "right".

Again:

_x += xSpeed;

if (....
speed = 13;

How can you not see this problem?

Darkblade
March 18th, 2008, 03:40 PM
Again:

_x += xSpeed;

if (....
speed = 13;

How can you not see this problem?

I don't understand what you are trying to say....



xSpeed = speed+10;
ySpeed = speed-(random(5)+11)

ArmoredSandwich
March 18th, 2008, 04:39 PM
Okay, I didn't see that. But that's where this problem is caused. You define xSpeed and ySpeed in the 'onClipEvent (load)'. You define using speed after you say speed is 13. So you can change the speed in the 'onClipEvent (enterFrame)', but it won't influence the xSpeed and ySpeed at all because you are not running that piece of code, you only ran it once when the object was created.

So what you need to do is put the if (_root.hale.right) in the 'onClipEvent (load)', and then it should work correctly.

Darkblade
March 18th, 2008, 05:19 PM
thanks mate! works like a charm now :) thanks again!

Darkblade
March 20th, 2008, 03:36 AM
One more thing is it possible to add a delay before or after the shot is made??

ArmoredSandwich
March 20th, 2008, 09:29 AM
One more thing is it possible to add a delay before or after the shot is made??

Never forget, everything's possible.

I think what you're looking for is in this topic: http://www.kirupa.com/forum/showthread.php?t=290592&

Darkblade
March 20th, 2008, 12:42 PM
Ok I will work on that now, just a quick problem I have encountered is that is that when I have a movie clip inside a movieclip and I want to have a hitTest on it with for example another MC. It doesn't seem to work? I do not know why?



onClipEvent (enterFrame) {
//normal attacks
if (!dead && !crouching && !jumping && !fight) {
if (Key.isDown(69)) {
_root.falcon.gotoAndStop("fpunch");
fight = true;
if (_root.falcon.falcon.fpunch.hitTest(_root.halo)) {
_root.hp2 -= strength+(random(11)+7);
}
}
}
}

ArmoredSandwich
March 20th, 2008, 01:20 PM
Ok I will work on that now, just a quick problem I have encountered is that is that when I have a movie clip inside a movieclip and I want to have a hitTest on it with for example another MC. It doesn't seem to work? I do not know why?



onClipEvent (enterFrame) {
//normal attacks
if (!dead && !crouching && !jumping && !fight) {
if (Key.isDown(69)) {
_root.falcon.gotoAndStop("fpunch");
fight = true;
if (_root.falcon.falcon.fpunch.hitTest(_root.halo)) {
_root.hp2 -= strength+(random(11)+7);
}
}
}
}


It should work, I think you got the path wrong.