all groups > flash actionscript > may 2005 >
You're in the

flash actionscript

group:

my pervasive function problem



my pervasive function problem Battletards
5/9/2005 12:00:00 AM
flash actionscript: 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?
Re: my pervasive function problem kglad
5/9/2005 12:00:00 AM
Re: my pervasive function problem Jeckyl
5/9/2005 12:00:00 AM
firstly, this line of code doens't do what you are saying it does

[quoted text, click to view]

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]

Re: my pervasive function problem Battletards
5/10/2005 12:00:00 AM
you guys are absolutely right!

Is the absolute value thing like this:
(math.abs(internaldistance))
?

.... and i've been checking that "while" loop over and over again, but I
don't see the problem with it. Pray tell, what is it?

Thanks!!!!

Andrew
Re: my pervasive function problem kglad
5/10/2005 12:00:00 AM
your while() statement:

while (_root[wallvar].hitTest(xcord+internaldistance), _root.player.y) {

Re: my pervasive function problem Jeckyl
5/10/2005 12:00:00 AM
[quoted text, click to view]

Math.abs(internaldistance)

you haveto get upper/lower case right in cae you publish for FP7

[quoted text, click to view]

I have no idea .. I could not see anything wrong

Did you put in the code I had there with the extra tracing ? .. then I may
be able to tell you what is going on when you show the trace output

Jeckyl

Re: my pervasive function problem Jeckyl
5/10/2005 12:00:00 AM
[quoted text, click to view]

aha .. good spotting kglad

its not the while loop itself per se .. its the call to hitTest and the ()
in the wrong place

the code is still sytactically correct, but is not doing what you expect it
to
--
Jeckyl

Re: my pervasive function problem Battletards
5/10/2005 12:00:00 AM
Oh, you know what? It looks like that hitTest just needed one more parenthesis.
while (_root[wallvar].hitTest((xcord+internaldistance), _root.player.y)) {
What a finicky little thing is flash!

Thanks everyone!!!!!
Re: my pervasive function problem kglad
5/10/2005 12:00:00 AM
AddThis Social Bookmark Button