PDA

View Full Version : how to use while?


0920357689
06-28-2010, 04:49
new smoke;
smoke = find_ent_by_class ( smoke, "toxicsmoke");
while(smoke != 0)
{
remove_entity(smoke);
smoke = find_ent_by_class ( smoke, "toxicsmoke");
}
use this will server dead

infek
06-28-2010, 23:25
new smoke;
smoke = find_ent_by_class ( smoke, "toxicsmoke");
while(smoke != 0)
{
remove_entity(smoke);
smoke = find_ent_by_class ( smoke, "toxicsmoke");
}
use this will server dead

what do you mean by "use this will server dead"

Mxnn
06-28-2010, 23:51
Statement while:
While condition is true, the loop will not stop.

zwfgdlc
06-29-2010, 03:17
new smoke = -1;
while((smoke = find_ent_by_class (smoke, "toxicsmoke"))
{
remove_entity(smoke);
}

NiHiLaNTh
06-29-2010, 04:34
new smoke = -1
while ( ( smoke = find_ent_by_class ( smoke, "toxicsmoke" ) ) > 0 )
{
remove_entity ( smoke )
}

GXLZPGX
06-29-2010, 04:52
Maybe he meant:

"Use this while server dead"

0920357689
06-29-2010, 05:01
Maybe he meant:

"Use this while server dead"
yes

my english very bad...sorry:cry:

this core is work

new smoke = -1
smoke = find_ent_by_class ( smoke, "toxicsmoke" )
while (smoke )
{
remove_entity ( smoke )
smoke = find_ent_by_class ( smoke, "toxicsmoke" )
}

JaGareN
06-29-2010, 09:31
@0920357689, you dont have to write this two times
smoke = find_ent_by_class ( smoke, "toxicsmoke" )

fysiks
06-29-2010, 17:51
@0920357689, you dont have to write this two times
smoke = find_ent_by_class ( smoke, "toxicsmoke" )

In his case he must.

YamiKaitou
06-29-2010, 18:16
FYI, -1 is considered True

JaGareN
06-29-2010, 19:05
In his case he must.

Why?

fysiks
06-29-2010, 19:06
FYI, -1 is considered True

If you are refering to me then I would assume that remove_entity(-1) would not be good. Hence why I said what I did :). But, maybe it wouldn't have a problem. IDK.

Edit: I just tried remove_entity(-1) and it didn't seem to complain.

YamiKaitou
06-29-2010, 19:37
Why?
Because he wants to remove all entities of that class

If you are refering to me then I would assume that remove_entity(-1) would not be good. Hence why I said what I did :). But, maybe it wouldn't have a problem. IDK.

Edit: I just tried remove_entity(-1) and it didn't seem to complain.
No, it was to anyone who was using while(smoke) since find_ent_by_class returns -1 and -1 is considered true.

FiFiX
10-13-2010, 18:11
Can someone explain this example with while condition?
The first post, and correct working looks like the same for me :(

Bugsy
10-13-2010, 19:18
It executes the code while the condition is met; repeatedly if the condition continues to be met. You can alter factors of the condition from within the code block.
while ( condition )
{
//do this code
}

Try
new smoke = -1;
while ( ( smoke = find_ent_by_class( smoke , "toxicsmoke" ) ) > 0 )
remove_entity( smoke )

FiFiX
10-14-2010, 05:11
while(find_ent_by_class (-1, "toxicsmoke"))
{
remove_entity(find_ent_by_class (-1, "toxicsmoke"));
}
But can someone explain me why that doesn't work? It seems to be "faster" and more optimal way..


TO BUGSY EXAMPLE:
And why in condition is -1? If entity haven't been fount, it returns 0, not -1 :/
So if
find ent != -1 (can be 0 - ent not found, and we are still deleting it...)

hleV
10-14-2010, 05:59
new Entity = -1;

while ((Entity = find_ent_by_class(Entity, "toxicsmoke")) > 0)
remove_entity(Entity);

Bugsy
10-14-2010, 09:11
Yes it should be 0, not -1. -1 is supposed to be specified if you do not wish to provide a starting entity.

http://www.amxmodx.org/funcwiki.php?go=func&id=344
If none is found, 0 is returned. If starting entity should not be specified, use -1.

fysiks
10-14-2010, 18:29
But can someone explain me why that doesn't work? It seems to be "faster" and more optimal way..

LOL. If it doesn't work then it is neither faster or optimal is it?