Author Topic: Client-sided container radius search: Infinite loop.  (Read 1504 times)

Code: [Select]
function clContainerRadius(%pos, %rad, %cl) {
$radiusPos = %pos;
$radiusRad = %rad;
$radiusCl = %cl;
$radiusID = 0;
}
function clContainerNext() {
%obj = -1;
while((!isObject(%obj = serverconnection.getobject($radiusID)) || %obj.getclassname() !$= $radiusCl || vectorSub($radiusPos, %obj.getPosition()) > $radiusRad) && $radiusID < serverConnection.getCount()-1)
                $radiusID++;
return %obj;
}
What the hell is the error? I just get a infinite loop when using this.

well ill try this and see wats going on

What the hell is the error? I just get a infinite loop when using this.
You'd probably understand a lot more about your code if you didn't squeeze it together in such a highly concentrated way.
There's a problem when nobody, including you, can read your code.

Let me dilute it into pseudocode so I can understand it.

Loop While...
  • ServerConnect(#) is not an object, or
  • the Object is not of specified class, or
  • it's not close enough, and
  • we're still in the range of the group.

Okay, after doing that I understand what the issue is.

if(%cond1 || %cond2 || %cond3 && %cond4)

is the same as

if(%cond1 || %cond2 || (%cond3 && %cond4))

That's doing it wrong. I explained this in one of my guides.

Here's the fix:

if((%cond1 || %cond2 || %cond3) && %cond4)
Code: [Select]
while(((!isObject(%obj = serverconnection.getobject($radiusID))
|| %obj.getclassname() !$= $radiusCl
|| vectorSub($radiusPos, %obj.getPosition()) > $radiusRad))
&& $radiusID < serverConnection.getCount() - 1)
                $radiusID++;

Here's the fix:

if((%cond1 || %cond2 || %cond3) && %cond4)
Code: [Select]
while(((!isObject(%obj = serverconnection.getobject($radiusID))
|| %obj.getclassname() !$= $radiusCl
|| vectorSub($radiusPos, %obj.getPosition()) > $radiusRad))
&& $radiusID < serverConnection.getCount() - 1)
                $radiusID++;

All you did was add parenthesis around something that already had parenthesis.

Original (spaced as if parenthesis were braces so you can comprehend it):
Code: [Select]
while
(
(
!isObject(%obj = serverconnection.getobject($radiusID))
||
%obj.getclassname() !$= $radiusCl
||
vectorSub($radiusPos,%obj.getPosition()) > $radiusRad
)
&&
$radiusID < serverConnection.getCount() - 1
)

Your "fix":
Code: [Select]
while
(
((
!isObject(%obj = serverconnection.getobject($radiusID))
||
%obj.getclassname() !$= $radiusCl
||
vectorSub($radiusPos,%obj.getPosition()) > $radiusRad
))
&&
$radiusID < serverConnection.getCount() - 1
)

yikes.

apparently I was just looking for the problem I hoped to see.

nice catch, I am having a really bad day today with code apparently.

Well, I'm not sure. I did find out one problem however, getPosition doesn't work for all objects.

What, exactly, is the allure of shoving all of that into one line?

What, exactly, is the allure of shoving all of that into one line?
Not knowing any better.

well ill try this and see wats going on
Don't worry everyone, this guy is on the case!

Anyway, I'd have it echo $radiusID SPC serverConnection.getCount() each iteration, just for debugging purposes.

You gotta love debugging.

And I just realized this was an unnecessary bump.

client side container radius search? :o