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
3 registered members (AndrewAMD, Ayumi, NewbieZorro), 14,141 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: problem with struct strings... [Re: EvilSOB] #403961
06/29/12 11:40
06/29/12 11:40
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
@evilsob: thats pretty much what i wanted him to do, too.

but your currect code has an issue: Since you are usign str_cpy on "placing_filename", i assume you have defined it as a STRING*.
you can not assign a STRING* directly to a char* like you do.
what you can do:
Code:
blocks[positchange.x][positchange.y][positchange.z].filename = _chr(placing_filename)


_chr is a build in macro that gives access to the char array thats stored inside the string.
Doing this is very dangerous!
whenever the STRING* placing_filename is changed (when it's size is changed more precisely), there is a high probability that the char* you've saved in the block is removed and thus points to invalid memory which will make the engine crash whenever you access it.
Additionally, all blocks then share the same char*, and so every block has the exact same value there, makeing it all pointless.

I'd still advise you to use my or Evilsobs solution. There is another solution however, which will be slow but not as slow as the 40 seconds STRING* thing. you'll have to set a fixed number of characters for the chars:

Code:
typedef struct
{ 	
	var locked;					//Switch if a block is placed or not
	var team;					//Wich Team is the block owner (MP)
	var passable;				//Is the block passable or not?
	var explored;				//Is there fog of war or not?
	var typus;					//typus_earth, typus_fire, typus_water
	var obj_rotatealpha;		//Turns the Block to alpha=60 if PAN is 180°?
	var positionx;				//The 3 block positions in this struct array
	var positiony;
	var positionz;
	var obj_pan;				//The object PAN rotation
	char objektname[32];			//The name of the Block
	char filename[32];			//The filename of the Block
	char setupname[32];			//The filename of the PAK file of the Block
	char contentname[32];		//The name of the WRS file the block is located in
	ENTITY* obj;				//The Block object itself
} BLOCK;

I chose 32 as fixed size, the more you chose the more memory you'll need. you can now use the c function strcpy (NOT str_cpy) to put data into those char*. no sys_malloc needed. EDIT: of course you'll need to see to it that placing_filename is never larger than 31 characters. the 32th character is needed for the null-termination of the char* (look it up if you don't know it).
Code:
strcpy(blocks[positchange.x][positchange.y][positchange.z].filename, _chr(placing_filename));



But you'll be using lots of memory. a single element of this struct now has a size of 172 Bytes. With your little level its 50*50*5*172 Bytes = 2150000 Bytes = ~ 2MB. Now multiply that with the level size you are aiming for and you'll be out of ram memory in no time.


Last edited by SchokoKeks; 06/29/12 11:43.
Re: problem with struct strings... [Re: SchokoKeks] #403968
06/29/12 14:31
06/29/12 14:31
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
so i need zo use 'char*' in a struct? cause i use STRING* in the structs too ...

the problem with the id method of you is, that the array wich stores the filenames, can be different on each run.. cause of new DLC or files
So storing the ID instead of the direct filename.. is a risky way ._.

Last edited by Espér; 06/29/12 15:49.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: problem with struct strings... [Re: Espér] #403986
06/29/12 23:12
06/29/12 23:12
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: Espér
so i need zo use 'char*' in a struct? cause i use STRING* in the structs too

You don't need to use char* in a struct. You can put anything you want in a struct. The point is that char* and STRING* are two totally different things and hence need different treatment. You cannot assign the result of str_create to a char pointer for example. And you must not use strcpy in combination with STRING*.


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