Raised This Month: $ Target: $400
 0% 

(Solved) [L4D] Where is logical mistake?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flynn
Senior Member
Join Date: Sep 2009
Old 10-01-2009 , 03:01   Re: [L4D] Where is logical mistake?
Reply With Quote #1

Quote:
Originally Posted by olj View Post
Ok, this code deletes medkits on every round start around first found survivor in 800 radius.
You could run at the very least a standard debugging approach by printing out the two vectors and the given distance to figure out why.

Your uh, entity code is what I'd call 'highly bastardised' (incredibly confusing - the more so, the more likely there are to be bugs in it).

Just to pick out some peices...
Code:
new ent = -1;
    while ((ent = FindEntityByClassname2(ent, "weapon_first_aid_kit_spawn")) != -1)
Code:
stock FindEntityByClassname2(startEnt, const String:classname[])
{
/* If startEnt isn't valid shifting it back to the nearest valid one */
while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
return FindEntityByClassname(startEnt, classname);
}
Bastardised parts highlighted. You're starting from -1, with a loop that breaks out on -1 (with a deincrementation operation), and returns ??? because FindEntity is given -1;

A better question is why is your code even able to remove medkits?

Edit: I presume FindEntity starts from -1, counts up, returns the first entity, the loop deincrements it back down, and because FindEntity only returns -1 when it -cannot find any more medkits- it gets trapped in an infinite loop until every single one is removed (which, when the player arrives at the finale spot, gets removed because the operation is still continuously operating - because there are still kits out there).

In short; Assumption and Presumption fail.

Quote:
Originally Posted by SourceMod Documentation
Return:
Entity index >= 0 if found, -1 otherwise.

Last edited by Flynn; 10-01-2009 at 03:10.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
MockingBird
Member
Join Date: Mar 2005
Old 10-01-2009 , 04:44   Re: [L4D] Where is logical mistake?
Reply With Quote #2

Quote:
Originally Posted by Flynn View Post
You could run at the very least a standard debugging approach by printing out the two vectors and the given distance to figure out why.

Your uh, entity code is what I'd call 'highly bastardised' (incredibly confusing - the more so, the more likely there are to be bugs in it).

Just to pick out some peices...
Code:
new ent = -1;
    while ((ent = FindEntityByClassname2(ent, "weapon_first_aid_kit_spawn")) != -1)
Code:
stock FindEntityByClassname2(startEnt, const String:classname[])
{
/* If startEnt isn't valid shifting it back to the nearest valid one */
while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
return FindEntityByClassname(startEnt, classname);
}
Bastardised parts highlighted. You're starting from -1, with a loop that breaks out on -1 (with a deincrementation operation), and returns ??? because FindEntity is given -1;

A better question is why is your code even able to remove medkits?

Edit: I presume FindEntity starts from -1, counts up, returns the first entity, the loop deincrements it back down, and because FindEntity only returns -1 when it -cannot find any more medkits- it gets trapped in an infinite loop until every single one is removed (which, when the player arrives at the finale spot, gets removed because the operation is still continuously operating - because there are still kits out there).

In short; Assumption and Presumption fail.
That code is fine. 'ent' is initted to -1 because the FindEntityByClassname looks for entities PAST the index given. If you want to start at 0, the index needs to be -1. The new entity found is then past into the 'ent' variable making it no longer equal to -1, and hence making the boolean expression true. Then after the loop, that new ent is then passed into the FindEntity function, and it starts again. The FindEntity function will return -1 when no entity is found, exitting the loop.

If no entity is found, the ent value will then be equal to -1, which is why his next code checks for the ent value to be greater than -1 so that it wont operate on a none existant entity.

I use this loop allot, and it works fine for me. I dont play L4D, so I cant help you with your actual problem xD
MockingBird is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode