Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 816 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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