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
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Pointers: How to remove Strings & Entities #243583
12/30/08 21:10
12/30/08 21:10
Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
D
Davidus Offline OP
Newbie
Davidus  Offline OP
Newbie
D

Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
Hello,

i have a pointer-understanding problem:
I wanted to write a little console,
but if i want to remove a string that should be displayed,
there is something strange:
It doesn't get removed, it simply stays,
and if i test with "if (currentString == NULL)" or
"if (!currentString)", the programm tells me the
string is still there.

I have also a problem with that on other places
of my programm, where i get errors because
i am accessing removed entitis,the problem there
is the same: a check on "Entity==NULL" doesn't success,
it tells me the entity was there and then crashes when
i access them!
(I won't list up all the code because thats the same problem, only in bigger!)

So how exactly do i get rid of a pointer and its content ?
Do i have to use ptr_remove, and additionally
set the variable to null by "variable = NULL" ?
I know it works if i set the variable on Null manually for strings, but this leads to the problem that i'm filling up my memory with Garbage.

Please, someone gimme an explanation here.

(I read the manual about that and i have some programming experience, but not in c-like languages)

Code:
STRING* currentString;
var consoleLifetime;

void print(STRING* str)
{
	consoleLifetime = 100;
	currentString = str;
}

void showConsole()
{
	if (!currentString)
	{
		return;
	}
	consoleLifetime--;
	draw_text(currentString,10,10, vector(255,255,255));
	if (consoleLifetime < 0)
	{
		ptr_remove(currentString);
	}
}


Spoken precisely,
i would need a function that removes an object,
and sets any pointer pointing to it to NULL,
not to an undefined state.
Unfortunately, the following had no effect,
because it only removes the local given pointer inside the function, not the pointers outside the function that i
really wanted to hit with that (like "currentString" in my previous example)
but i need something in the style of this:

Code:
void delete (ENTITY* ent)
{
	ptr_remove (ent);
	ent = NULL;
}


Last edited by Davidus; 12/30/08 21:37.
Re: Pointers: How to remove Strings & Entities [Re: Davidus] #243835
01/01/09 02:20
01/01/09 02:20
Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
D
Davidus Offline OP
Newbie
Davidus  Offline OP
Newbie
D

Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
C'mon ,

you cannot tell me that nobody here knows how to deal with pointers ^^

if it has a reason that nobody answers me, please be polite/honest and tell me what's wrong with my post, i am willing to learn if my post was in some kind unfitting or too noobish or whatever.
When i finnally have enough knowledge, i will gladly help other noobs out but at the moment i'm a noob by myself laugh

Re: Pointers: How to remove Strings & Entities [Re: Davidus] #243871
01/01/09 10:36
01/01/09 10:36
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
hey,

really you shouldn't be removing pointers unless you're sure you won't be using them again,

you only need to change the contents of the pointer to NULL,

Re: Pointers: How to remove Strings & Entities [Re: MrGuest] #243873
01/01/09 10:43
01/01/09 10:43
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
use "ptr_remove(POINTER_NAME);"

Re: Pointers: How to remove Strings & Entities [Re: Cowabanga] #243907
01/01/09 16:52
01/01/09 16:52
Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
D
Davidus Offline OP
Newbie
Davidus  Offline OP
Newbie
D

Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
okay but what's the alternative ?

For Strings i can indeed simply set it to null,
but if i remove an entity, how do i get removed all pointers pointing to this thing.

Let's say i had an entity, and 3 monsters who have this entity as a target pointer -
if i removed theentity, the pointers of the 3 monsters are not NULL but INVALID instead, and i'm searching for a way to remove things and remove their pointers as well.

I had another idea: setting on of the 8 flags to null, and let the things remove themselves when they are in their loop - is that a good idea, or how do you remove your entitis, that's what i'm looking for !

By the way, Thanks for the replies so far!

Re: Pointers: How to remove Strings & Entities [Re: Davidus] #243941
01/01/09 20:11
01/01/09 20:11
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
use
ent_remove(ENTITY*);

any pointer pointing to an entity that's been removed will then return NULL

Re: Pointers: How to remove Strings & Entities [Re: MrGuest] #243951
01/01/09 20:56
01/01/09 20:56
Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
D
Davidus Offline OP
Newbie
Davidus  Offline OP
Newbie
D

Joined: Jun 2008
Posts: 24
germany --> nrw --> aachen
Hey MrGuest,

that's what i thought, but it's not.
If i have 3 pointers pointing to X,
and i do ent_remove on pointer nr.1 , then all three
pointers are still pointing to it's adress,
and are causing bugs if called ... that exactly is my problem.


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