Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,103 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Return value of c_trace? #416813
02/05/13 01:33
02/05/13 01:33
Joined: Jan 2013
Posts: 63
Loremaster Offline OP
Junior Member
Loremaster  Offline 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.

Code:
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 Offline
Expert
WretchedSid  Offline
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: WretchedSid] #416815
02/05/13 02:43
02/05/13 02:43
Joined: Jan 2013
Posts: 63
Loremaster Offline OP
Junior Member
Loremaster  Offline OP
Junior Member

Joined: Jan 2013
Posts: 63
Got it. There is a me, there is a you. The latter was unknown to me. laugh

Re: Return value of c_trace? [Re: Loremaster] #416816
02/05/13 06:15
02/05/13 06:15
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
BTW.: To avoid "empty pointer" errors please check YOU before using it fex.:
Code:
c_trace
 if (you) if (you == player)



Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
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 Offline
Expert
WretchedSid  Offline
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: WretchedSid] #416818
02/05/13 06:42
02/05/13 06:42
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Ah ok.
so this is ok:
Code:
if (you == player)



and the check is only needed here
Code:
if (you) you.health -= 10;



Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
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 Offline
Expert
WretchedSid  Offline
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:

Code:
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: WretchedSid] #416820
02/05/13 07:07
02/05/13 07:07
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Code:
if (you) if (you == player) you.health-=10;

This is how i use to make it (almost ever). Guess its the most secured way.


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
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 Offline
Expert
WretchedSid  Offline
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
Re: Return value of c_trace? [Re: WretchedSid] #416822
02/05/13 07:24
02/05/13 07:24
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
I just wanted to say if hes not sure if you != 0 he should check it before.
But i got your points, thank you.


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1