|
|
if(player) versus while(player == 0)
#294136
10/16/09 14:52
10/16/09 14:52
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Can anybody tell me, why the first thing works, but the latter not? The first is waiting while the pointer 'player' is empty. The second and third version tests whether 'player' is valid. What's wrong with that?
while(player == 0){wait(1);}
while(1)
{
// if(player == 1)
// {
if(vec_dist(player.x, my.x) < 200)
{
sound();
}
// }
wait(1);
}
//while(player == 0){wait(1);}
while(1)
{
if(player == 1)
{
if(vec_dist(player.x, my.x) < 200)
{
sound();
}
}
wait(1);
}
//while(player == 0){wait(1);}
while(1)
{
if(player)
{
if(vec_dist(player.x, my.x) < 200)
{
sound();
}
}
wait(1);
}
|
|
|
Re: if(player) versus while(player == 0)
[Re: Scorpion]
#294148
10/16/09 16:20
10/16/09 16:20
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Thanks for your reply! you(player==1) will probably return false and so not execute the branch, because the variable is with a high probability not 1.
This was the reason, why I tried the third version: 'if(player)' - isn't any value above zero true?
|
|
|
Re: if(player) versus while(player == 0)
[Re: Pappenheimer]
#294150
10/16/09 16:26
10/16/09 16:26
|
Fear411
Unregistered
|
Fear411
Unregistered
|
Try it like this:
while(1)
{
if(player != NULL)
{
if(vec_dist(player.x, my.x) < 200)
{
sound();
}
}
wait(1);
}
|
|
|
|