Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,618 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: dynamic array in structs [Re: Uhrwerk] #417123
02/08/13 17:37
02/08/13 17:37
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
Code:
WEAPON* setup_template_weapon(WEAPON* w_template)  //a init routine
{
	// Speicherbereich reservieren
 	WEAPON* w = sys_malloc(sizeof(WEAPON));
 
 	// Mit den Daten der vorlage füllen
 	memcpy(w,w_template,sizeof(WEAPON));
     	
	// Liefere den Pointer an den zurück
   return w;
}


Re: dynamic array in structs [Re: Abarudra] #417130
02/08/13 18:56
02/08/13 18:56
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Thanks. And how did you declare "Basiswaffe" ?


Always learn from history, to be sure you make the same mistakes again...
Re: dynamic array in structs [Re: Uhrwerk] #417132
02/08/13 19:43
02/08/13 19:43
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
sry for the late reply.

first WEAPON* Basiswaffe;

and then in an startupfunction
[code]
Basisturret = sys_malloc(sizeof(TURRET));
Basisturret.t_name = "Testturret";
Basisturret.t_gun_amount = 1;

(Basisturret.t_guns) = (WEAPON*)sys_malloc(Basisturret.t_gun_amount*sizeof(WEAPON));

var i = 0;
for(i=0;i< Basisturret.t_gun_amount;i++)
{
(Basisturret.t_guns)[i] = setup_template_weapon(Basiswaffe);
}

thanks

Re: dynamic array in structs [Re: Abarudra] #417133
02/08/13 19:55
02/08/13 19:55
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Ah, ok, now I got it. t_guns is a pointer to a WEAPON struct or a an array of WEAPON structs (i.e. a poiner to multiple WEAPON structs following directly on each other in memory). Hence (Basisturret.t_guns)[i] is of type WEAPON. But setup_template_weapon returns a pointer to a WEAPON struct. There you got the incompatible types, namely WEAPON vs. WEAPON*. I guess what you want to have is an array of pointers to WEAPON structs, right? In this case you have to declare it as WEAPON** in the struct definition.


Always learn from history, to be sure you make the same mistakes again...
Re: dynamic array in structs [Re: Uhrwerk] #417134
02/08/13 20:08
02/08/13 20:08
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
i will try it thanks

Re: dynamic array in structs [Re: Abarudra] #417136
02/08/13 21:12
02/08/13 21:12
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
works like a charm, but i have one final question (i hope laugh
I use this function to attach the weapon entitys to the turretentity

Code:
void add_weapon_to_bearer(WEAPON* w,vertex)
{
	vec_for_vertex(my._hinge_pos,me,vertex);
	w.w_me = ent_create(w.w_gun_model,my._hinge_pos,w.w_gun_func);
	w.w_me._stat_pointer = w;
}

w_me is an entitypointer to the weaponmodel


And use it this way
Code:
for(i=0;i<t.t_gun_amount;i++)
	{
		// Aufhängepunkt
		my.skill[4+i]	= (t.t_hinge)[i];
		// Waffebefestigen
		add_weapon_to_bearer((t.t_guns)[i],my.skill[4+i]);
	}



it compiles without error but the attaching function crashes when first called

Re: dynamic array in structs [Re: Abarudra] #417137
02/08/13 21:26
02/08/13 21:26
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I can't help you just from looking at the code. Please specify which line is giving you the crash. You can place a beep() at the beginning of the function. If you hear the beep before the crash place it one line further down until the crash happens before the beep().


Always learn from history, to be sure you make the same mistakes again...
Re: dynamic array in structs [Re: Uhrwerk] #417143
02/08/13 22:29
02/08/13 22:29
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
i found out that it is not the function itself that is causing the crash, but one of the turret structs that has more than one weapon assinged to it that is causing an e1513 error. But this is now my job and not yours.
I will look through my complete code and try to find the error by myself and stop wasting your time. Thank you very much, you brought me a very large step forward in my project. Good night.

Regards

Re: dynamic array in structs [solved] [Re: Abarudra] #417152
02/09/13 08:57
02/09/13 08:57
Joined: Mar 2012
Posts: 44
A
Abarudra Offline OP
Newbie
Abarudra  Offline OP
Newbie
A

Joined: Mar 2012
Posts: 44
I found my error (a quite embarrassing too).
I had an "old" line in my code which asigns a pointer to the wrong struct and that caused the crash.
Now the code works absolutely fine and does exactly what i want.

kind regards

Re: dynamic array in structs [solved] [Re: Abarudra] #417167
02/09/13 14:40
02/09/13 14:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I'm glad you figured it out! laugh


Always learn from history, to be sure you make the same mistakes again...
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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