firstly, this line of code doens't do what you are saying it does
[quoted text, click to view] >>>> internaldistance = ((internaldistance*2)-internaldistance);
that does not change the value of internaldistance at all ... it remains the
same. Use Math.abs to force a value to positive
Anyway ... put in more tracing so you DO get something comming out like
this, and then tell us what you DO get
function wallcheck (direction) {
//direction 1=R, -1=L
if (direction == 1) {
var xcord=(_root.player.x+9+(_root.player.speed));
} else {
var xcord=(_root.player.x-9-(_root.player.speed));
}
trace("xcord="+xcord);
for (var i = 1; i < 3; i++) {
var wallvar = ("wall"+i);
trace("wallvar="+wallvar);
if (_root[wallvar].hitTest(xcord, _root.player.y)) {
trace ("inwall");
var internaldistance = 0;
while (_root[wallvar].hitTest(xcord+internaldistance),
_root.player.y) {
if (direction == 1) {
internaldistance--;
} else {
internaldistance++;
}
trace ("inloop internaldistance="+internaldistance);
}
internaldistance = ((internaldistance*2)-internaldistance); //
<<< weird code
if ((internaldistance>0) and
(internaldistance<_root.player.speed)) {
_root.player.speed -= internaldistance;
trace("_root.player.speed="+_root.player.speed);
}
trace("returning yes");
return "yes"; //this should exit the function, right? YES
}
}
trace("retuning no");
return "no";
}
--
Jeckyl
[quoted text, click to view] "Battletards" <webforumsuser@macromedia.com> wrote in message
news:d5oqi8$7sp$1@forums.macromedia.com...
> Hi, everyone. Thanks for all the help that you all have given me on my
> function. However, my problem still persists.
>
> I have this function (see below), that just seems to stall out at a
> certain
> point. It's not entering an endless loop; i know this because i put a
> trace
> command in all my loops to see if i'd get the same message traced infitite
> times, but it doesn't even trace once.
>
> Here's the script. Flash just stops when the "player" MC hits the "wall"
> MC.
> Do you want to see the script that calls this function?
>
> function wallcheck(direction) {//direction 1=R, -1=L
> if (direction == 1) {
> var xcord=(_root.player.x+9+(_root.player.speed));
> } else {
> var xcord=(_root.player.x-9-(_root.player.speed));
> }
> for (var i=1;i<3;i++) {
> var wallvar = ("wall"+i);
> if (_root[wallvar].hitTest(xcord, _root.player.y)) {
> trace ("inwall");
>
> var internaldistance = 0;
> while
> (_root[wallvar].hitTest(xcord+internaldistance),
> _root.player.y) {
> if (direction == 1) {
> internaldistance--;
> } else {
> internaldistance++;
> }
> trace ("inloop");
> }
> internaldistance =
> ((internaldistance*2)-internaldistance);//this just makes neg into pos
> if ((internaldistance>0) and
> (internaldistance<_root.player.speed)) {
> _root.player.speed -= internaldistance;
> }
> return "yes";//this should exit the function,
> right?
> }
> }
> return "no";
> }
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Thanks!!!!!
> PS
> Patrick, where do you place that global variable stuff? Is that the way
> to
> CALL the function? or is that the first line of the function? what?
>