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
2 registered members (AndrewAMD, TipmyPip), 12,400 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
initialize arrays in structs. #312135
02/23/10 13:27
02/23/10 13:27
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
How can i initialize a struct like this:
Code:
typedef struct
{
var test[3];
}teststruct;



This doesnt work
Code:
teststruct* bla=
{
 test[0]=1; test[1]=2; test[2]=1;
}


Neither this:
Code:
teststruct* bla=
{
 test={1,2,3};
}


whats the right way to do it?

Last edited by Puppeteer; 02/23/10 13:28.

Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: initialize arrays in structs. [Re: Puppeteer] #312137
02/23/10 13:33
02/23/10 13:33
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Code:
typedef struct
{
	var test[3];
}teststruct;
	
teststruct* bla() {
	teststruct* tempStruct = sys_malloc( sizeof(teststruct) );
	
	var i;
	for(i=0; i<3; i++) {
		tempStruct.test[i] = 0;
	}
	
	return(teststruct);
}



I have it like that, should work.

regards,

Last edited by Helghast; 02/23/10 13:36. Reason: sys_malloc, not sys_nxalloc for this :)

Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: initialize arrays in structs. [Re: Helghast] #312139
02/23/10 13:39
02/23/10 13:39
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Yeah, you have to do it manually:

"Array initialization in the array definition has several restrictions: It is not supported for structs..." (manual - variables and arrays)

Re: initialize arrays in structs. [Re: Helghast] #312140
02/23/10 13:39
02/23/10 13:39
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Hm but this is a function. I'd like to initilize it while compiling.
So i can create some data in the scripts (i will use it for some animation stuff like this:
Code:
MM_MOVE_MODE* cbabe_walk_state=
{
	moves[1]=walk_forwardrrr;
	moves[2]=walk_forwardrr;
	moves[3]=walk_forwardr;
	moves[4]=walk_forward;
	moves[5]=walk_forwardl;
	moves[6]=walk_forwardll;
	moves[7]=walk_forwardlll;
	moves[8]=NULL;
	moves[9]=NULL;
	moves[10]=NULL;
	moves[11]=NULL;
	moves[12]=NULL;
	moves[13]=NULL;
	moves[14]=NULL;
	moves[15]=NULL;
	num_moves=8;
}


and i dont want to initialize it at runtime since things would get reeeeeaaally messy then.


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: initialize arrays in structs. [Re: Puppeteer] #312149
02/23/10 13:59
02/23/10 13:59
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Just in case you havn't seen my reply (as there were just a few seconds between our posts): Obviously initializing arrays in structs has to be done manually (see post above).

Re: initialize arrays in structs. [Re: Saturnus] #312150
02/23/10 14:01
02/23/10 14:01
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
=( Baaaad news.
Thank you


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: initialize arrays in structs. [Re: Helghast] #313982
03/04/10 20:13
03/04/10 20:13
Joined: Dec 2009
Posts: 2
New York, NY
calculus Offline
Guest
calculus  Offline
Guest

Joined: Dec 2009
Posts: 2
New York, NY
Helghast,

I had a similar question, but had difficulty getting your code to work, and I wondered if you meant "return(tempStruct)" instead of "return(teststruct)"?


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