Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,486 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Entity pointer to a removed entity #334205
07/21/10 19:31
07/21/10 19:31
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
Hi,

how can I check if an entity pointer (not me or you) points to an entity which has removed allready? I tried if(handle(ent) = -1) {...} but it doesn't work. Hope there's a very simple way.


Thanks for reading, thinking, answering wink
Re: Entity pointer to a removed entity [Re: Toryno] #334207
07/21/10 19:42
07/21/10 19:42
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
After removing an entity, set its pointer to NULL. Then you can always check if(ent) {...} wink

Re: Entity pointer to a removed entity [Re: Lukas] #334209
07/21/10 20:08
07/21/10 20:08
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
From the manual:
"All my and you pointers to that entity are set to NULL in all functions."
The pointer I'm using is a self-declarated. This isn't set to NULL and it's not global so I can't set in to NULL myself.


Thanks for reading, thinking, answering wink
Re: Entity pointer to a removed entity [Re: Toryno] #334210
07/21/10 20:19
07/21/10 20:19
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Well, then you just have to check if(you) {...} and if you remove an entity in its action, just put a return; after the remove.

Re: Entity pointer to a removed entity [Re: Lukas] #334216
07/21/10 20:30
07/21/10 20:30
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
It seems that this doesn't work. Ok here's my code.

You see: In the second frame, victim points to an entity which has allready been removed so the engine crashes.

Code:
ENTITY* jet = ent_create(...);

function example() {
	wait(1);
	ent_remove(jet);
}

action turret() {
	ENTITY* victim = jet;
	
	...
	while(1)
		if (victim != NULL) {
			victim.LIFE -= time_step; // crash
		}
	}
}



Last edited by Toryno; 07/21/10 20:45. Reason: i wrote an example to the code to make in more unsterstandable

Thanks for reading, thinking, answering wink
Re: Entity pointer to a removed entity [Re: Toryno] #334219
07/21/10 20:42
07/21/10 20:42
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Only the "me" and "you" pointers are automatically set to NULL when an entity is removed. Your "victim" pointer is not set to NULL. So, your "if (victim != NULL)" or "if(victim)" make no sense as they are always true.

You must not remove an entity as long as its pointer is still used in another function. Terminate that function first.

Re: Entity pointer to a removed entity [Re: Petra] #334221
07/21/10 20:50
07/21/10 20:50
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Or, as I said, set jet and victim to NULL. If you don't always know which other pointers also point to the entity, you could use ENTITY** pointers that all point to one pointer you can set to NULL.

Re: Entity pointer to a removed entity [Re: Lukas] #334225
07/21/10 21:43
07/21/10 21:43
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
Entity** is a good idea I will make that. wink thanks


Thanks for reading, thinking, answering wink
Re: Entity pointer to a removed entity [Re: Toryno] #334262
07/22/10 06:36
07/22/10 06:36
Joined: Sep 2007
Posts: 62
Germany
B
bodden Offline
Junior Member
bodden  Offline
Junior Member
B

Joined: Sep 2007
Posts: 62
Germany
I'm not in front of my 3dgs-PC, so I'm not sure. But you could try

Quote:
if (victim == jet)


instead of

Quote:
if (victim != NULL)


Or use
Quote:
if (victim != jet) { victim = null; }
insisde the while {}

Re: Entity pointer to a removed entity [Re: bodden] #334290
07/22/10 10:56
07/22/10 10:56
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
you should also be able to use
Code:
if(ptr_first(victim) != NULL)


Because if 'victim' is no longer pointing to a valid entity,
ptr_first will return a NULL...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 1 of 2 1 2

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