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
2 registered members (AndrewAMD, alibaba), 1,426 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
question about you pointer #411632
11/18/12 13:29
11/18/12 13:29
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Hi all,

i have a question about saving and checking the you pointer.

Code:
function carried_ent()
{
 //ENTITY* carrier = you;
 while(you)
 {	
	vec_for_vertex(my.skill30,you,141);
  	vec_set(my.x,my.skill30);

        //some additional code

	wait(1);
 }
 ent_remove(me);
}



The code above is working fine. This entity has to exist as long as its creator exists. "You" is pointing to the creating entity, but what i would like to know:
- if i add code in the loop that alters the you pointer like c_scan or c_trace, will "while(you)" check if the creator or the target of scan/trace still exists?

if i change the code above like this its no longer working
Code:
function carried_ent()
{
 ENTITY* carrier = you;
 while(carrier)
 {	
	vec_for_vertex(my.skill30,carrier,141);
  	vec_set(my.x,my.skill30);

        //some additional code

	wait(1);
 }
 ent_remove(me);
}


I guess cause i only set it once, "carrier" doesn`t know that the creator was removed.
If i replace "while(carrier)" with "while(carrier==you)" its working again, but i dont know whether i will get the same problem as with the first codeexample.
Any suggestions? I`m thankfull for your help.

Regards

Re: question about you pointer [Re: Abarudra] #411634
11/18/12 14:11
11/18/12 14:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: Abarudra
if i add code in the loop that alters the you pointer like c_scan or c_trace, will "while(you)" check if the creator or the target of scan/trace still exists?

No, it will not. But you can work around this quite easily.
Code:
while (you)
{
    ENTITY* temp_you = you;
    // Do any stuff that changes you here, like c_trace etc.
    you = temp_you;
}


Last edited by Uhrwerk; 11/18/12 14:42. Reason: Fixed a spelling mistake in the code sample.

Always learn from history, to be sure you make the same mistakes again...
Re: question about you pointer [Re: Uhrwerk] #411635
11/18/12 14:17
11/18/12 14:17
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Vielen Dank. Ich merke das ich einfach immer zu kompliziert denke. Auf so nen einfachen Workaround wäre ich nicht gekommen. Ihr hab es echt drauf.

Edit: tut mir leid für den Nachtrag.

Wie kann ich prüfen das die Entity auf die mein Entitypointer verweist noch existiert, ohne Skills oder FLAGs dieser zu prüfen?

Last edited by Abarudra; 11/18/12 14:26.
Re: question about you pointer [Re: Abarudra] #411637
11/18/12 14:40
11/18/12 14:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
The you and me pointer will automatically be set to NULL when the corresponding entity gets removed, so you don't need to take extra care about that.

When using custom pointers there is no way to check if the entity exists. The pointer just contains an address, regardless if the entity exists or has already been destroyed. Accessing such a pointer will always result in a crash or worse - overwriting random memory and a crash later on. ^^

If you don't want to use the me or you pointer you better switch to handles. You can get an entities handle by calling the handle(ENTITY*) function and can check if the enity still exists by calling ptr_for_handle(fixed). This function will return NULL if there is no entity with the given handle.


Always learn from history, to be sure you make the same mistakes again...
Re: question about you pointer [Re: Uhrwerk] #411640
11/18/12 14:45
11/18/12 14:45
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Thank you very much Uhrwerk. I am very grateful for your help. Have a nice day!

Re: question about you pointer [Re: Abarudra] #411644
11/18/12 14:55
11/18/12 14:55
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You're welcome. :-)


Always learn from history, to be sure you make the same mistakes again...

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