0 registered members (),
18,767
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: dynamic array in structs
[Re: Uhrwerk]
#417123
02/08/13 17:37
02/08/13 17:37
|
Joined: Mar 2012
Posts: 44
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
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
Expert
|
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: Abarudra]
#417133
02/08/13 19:55
02/08/13 19:55
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
|
|
|
Re: dynamic array in structs
[Re: Abarudra]
#417136
02/08/13 21:12
02/08/13 21:12
|
Joined: Mar 2012
Posts: 44
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
works like a charm, but i have one final question (i hope  I use this function to attach the weapon entitys to the turretentity
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
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
Expert
|
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...
|
|
|
|