Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 06/30/24 02:01
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (bigsmack), 1,009 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Multidimensional Array of STRINGS [Re: MasterQ32] #407233
09/09/12 22:05
09/09/12 22:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Yeah... dirty#1 is DIRTY, dirty#2 is just a bad habit...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Multidimensional Array of STRINGS [Re: PriNova] #407930
09/21/12 10:34
09/21/12 10:34
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline
Junior Member
PriNova  Offline
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
So, now the next example is not an array of strings but an array of entity. Here a simple sphere. i tried to initialize an array of 10 spheres and set it with .x to a specified position, but it doesn't work.
i watch it with DEBUG_VAR if my vector is set correctly and it is.
then i give the positions to every sphere, that they form a row of spheres, but all spheres has the same position.
Maybe i fall into a trap of restrictions i oversee or my pointers are wrong allocated.

Code:
ENTITY sec[10];
int i;

function main()
{
   i = 10;
   sec = malloc(sizeof(ENTITY)*i);
   for(v=0;v<i;v++)
	{
		&sec[v] =  ent_create("SPHERE.MDL", NULL,NULL);
		&sec[v].flags = SHOW;
	}
	
	for(v=0;v<i;v++)
	{
		vec_set(sec[v].x, vector(v*3,0,0));
		wait(1);
		DEBUG_VAR(sec[3].x,30);
	}
}



what my initial code should do is. that i create a master sphere, and put at every vertex, a smaller sphere:

Code:
ENTITY *fis;
int i;

void main()
{
...
fis = ent_create("SPHERE.MDL", vector(0,0,0),NULL);
i = ent_status(fis,1);
...
}



After that i get all vertices from the CONTACT struct of the Master Sphere.
And (try to) put the smaller spheres with a for..loop on them, if the positioning would work.

arggghh.

Re: Multidimensional Array of STRINGS [Re: PriNova] #407934
09/21/12 14:26
09/21/12 14:26
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
ENTITY sec[10];


This is an array of entity structs. But you want to have an array of pointers to entities, right?
Code:
sec = malloc(sizeof(ENTITY)*i);


That's wrong. First you already defined and initialized sec. It already is an array of ENTITY structs and it's allocated as sec is static. Second you allocate too much memory. You don't need to allocate space for a complete ENTITY struct. The engine does that when you call ent_create. So you just need space for the pointers to the entities and that would be:
Code:
sec = malloc(sizeof(ENTITY*)*i);


Note the star behind ENTITY.

You have to decide what you want to do. For a static array of pointers to entities
Code:
ENTITY* sec[10];

will be sufficient. No further allocation is required then. When you want to dynamically create the array you should use
Code:
ENTITY** sec = sys_malloc(sizeof(ENTITY*) * NUMBER_OF_ELEMENTS);





Always learn from history, to be sure you make the same mistakes again...
Re: Multidimensional Array of STRINGS [Re: Uhrwerk] #407970
09/22/12 13:01
09/22/12 13:01
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline
Junior Member
PriNova  Offline
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
Thank you uhrwerk. I simply forgot the double '*' with the ENTITY initialization.

Page 3 of 3 1 2 3

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