| Blockland Forums > Modification Help |
| Client-sided container radius search: Infinite loop. |
| (1/3) > >> |
| Bauklotz:
--- Code: ---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; } --- End code --- What the hell is the error? I just get a infinite loop when using this. |
| clinr121:
well ill try this and see wats going on |
| Iban:
--- Quote from: Bauklotz on March 05, 2011, 08:47:39 AM ---What the hell is the error? I just get a infinite loop when using this. --- End quote --- 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: --- while(((!isObject(%obj = serverconnection.getobject($radiusID)) || %obj.getclassname() !$= $radiusCl || vectorSub($radiusPos, %obj.getPosition()) > $radiusRad)) && $radiusID < serverConnection.getCount() - 1) $radiusID++; --- End code --- |
| Truce:
--- Quote from: Iban on March 05, 2011, 01:01:58 PM ---Here's the fix: if((%cond1 || %cond2 || %cond3) && %cond4) --- Code: --- while(((!isObject(%obj = serverconnection.getobject($radiusID)) || %obj.getclassname() !$= $radiusCl || vectorSub($radiusPos, %obj.getPosition()) > $radiusRad)) && $radiusID < serverConnection.getCount() - 1) $radiusID++; --- End code --- --- End quote --- 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: ---while ( ( !isObject(%obj = serverconnection.getobject($radiusID)) || %obj.getclassname() !$= $radiusCl || vectorSub($radiusPos,%obj.getPosition()) > $radiusRad ) && $radiusID < serverConnection.getCount() - 1 ) --- End code --- Your "fix": --- Code: ---while ( (( !isObject(%obj = serverconnection.getobject($radiusID)) || %obj.getclassname() !$= $radiusCl || vectorSub($radiusPos,%obj.getPosition()) > $radiusRad )) && $radiusID < serverConnection.getCount() - 1 ) --- End code --- |
| Iban:
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. |
| Navigation |
| Message Index |
| Next page |