Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 7th_zorro), 892 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
how to change entity pointer within a function #329233
06/18/10 17:43
06/18/10 17:43
Joined: Oct 2002
Posts: 806
Zapan@work Offline OP
User
Zapan@work  Offline OP
User

Joined: Oct 2002
Posts: 806
I want to create a small list of Entites. For this I want to connect each pointer with its neighbours (prev, next), a simple linked list... The problem is that I cant change the given first/last pointer so it becomes valid outside the function scope:

#include <acknex.h>
#include <default.c>

ENTITY* pEmeter_first;
ENTITY* pEmeter_last;

#define ent_nextListObj skill97

//Add an object to the list
void ent_listAdd(ENTITY* p, ENTITY** first, ENTITY** last)
{
if (first == NULL) {
&first = &p;
&last = &p;
return;
}

last.ent_nextListObj = &p;
last = &p;
}

void main()
{
level_load(NULL);

wait(2);

pEmeter_first = NULL;
pEmeter_last = NULL;

ENTITY* p = ent_create(CUBE_MDL,nullvector,NULL);

ent_listAdd(p, &pEmeter_first, &pEmeter_last);

if (p == pEmeter_first) {
error("JUP!");
} else {
if (pEmeter_first == NULL) {
error("URGHS!");
} else {
error("???");
}
}
}


I want to see a "JUP" on my screen, so maybe you can help me? laugh

I've also uploaded the testfile here:
http://user.crew51.com/weinhold/main.c

Re: how to change entity pointer within a function [Re: Zapan@work] #329240
06/18/10 18:06
06/18/10 18:06
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
This gives you a JUP:

Code:
#include <acknex.h>
#include <default.c>

ENTITY* pEmeter_first;
ENTITY* pEmeter_last;

#define ent_nextListObj skill97

//Add an object to the list
void ent_listAdd(ENTITY* p, ENTITY** first, ENTITY** last)
{
	if (*first == NULL) {
		*first = p;		
		*last = p;
		return;
	} 
	
	last.ent_nextListObj = p;
	last = p;	
}

void main() 
{
	level_load(NULL);
	
	wait(2);
	
	pEmeter_first = NULL;
	pEmeter_last = NULL;
	
	ENTITY* p = ent_create(CUBE_MDL,nullvector,NULL);	
	
	ent_listAdd(p, &pEmeter_first, &pEmeter_last);

	if (p == pEmeter_first) {
		error("JUP!");
	} else {	
		if (pEmeter_first == NULL) {
			error("URGHS!");
		} else {
			error("???");
		}
	}
}



&object returns a pointer to "object", *object returns the object "object" points to.

But are you aware that p.ent_nextListObj points to the entity itself if it's the first entity in the list?

Re: how to change entity pointer within a function [Re: Lukas] #329586
06/21/10 12:39
06/21/10 12:39
Joined: Oct 2002
Posts: 806
Zapan@work Offline OP
User
Zapan@work  Offline OP
User

Joined: Oct 2002
Posts: 806
Thank you, everything is working fine now.. laugh


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