0 registered members (),
1,103
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Return value of c_trace?
#416813
02/05/13 01:33
02/05/13 01:33
|
Joined: Jan 2013
Posts: 63
Loremaster
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2013
Posts: 63
|
I use the following line of code to evaluate whether there is a line of sight between player and NPC.
if (c_trace(
my.x,
player.x,
IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES) == 0)
{
FancyNPCFunction()
}
I assumed if the trace hits the player unhindered, the return value would be 0. My if-statement therefore triggers the NPC-action if it is 0. It does not trigger it. What do I do wrong?
|
|
|
Re: Return value of c_trace?
[Re: Loremaster]
#416814
02/05/13 02:30
02/05/13 02:30
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
c_trace returns 0 when nothing is hit, otherwise the return value is non-zero. Note though that hit could mean that anything was hit, not just the player, so you should check wether you is equal to the player.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Return value of c_trace?
[Re: rayp]
#416817
02/05/13 06:36
02/05/13 06:36
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
That's not needed Rayp, you can compare a nullpointer to any other pointer just fine, you just can't dereference it.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Return value of c_trace?
[Re: rayp]
#416819
02/05/13 06:56
02/05/13 06:56
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
If you can guarantee that player is always unequal to NULL, you can omit the second check and just access you directly (given that both if() are related obviously). This would also work if you don't know wether player is NULL or not:
if(you && you == player)
{
you->health -= 10;
}
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Return value of c_trace?
[Re: rayp]
#416821
02/05/13 07:09
02/05/13 07:09
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
It's not though. Like I said, if you know that player is always unequal to NULL, you can simply remove the check wether you is NULL or not, because if it is equal to player, it's definitely not NULL. If you don't know if player is NULL or not, you can put the check wether you is NULL or not together into the same if and make your code cleaner and easier to read
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|