Structures messed up

Just starting out? Need help? Post your questions and find answers here.
Diaco
New User
New User
Posts: 2
Joined: Mon Jun 21, 2021 3:06 pm

Structures messed up

Post by Diaco »

Hello guys. :)
I need to ask…
Why arrays are not generating in output file?
Am i doing something wrong?

Code: Select all

#Bitplanes	=	5
#Colors	=	32
#Width	=	16
#Height	=	16


Structure sPitch
	
	PixelLine.b[#Width/8]
	
EndStructure
Structure sLine
	
	Array PixelLine.sPitch(#Bitplanes-1)
	
EndStructure
Structure sBODY
	
	tagBODY.l
	length.l
	Array Line.sLine(#Height-1)
	
EndStructure
Structure sRGB
	
	R.b
	G.b
	B.b
	
EndStructure
Structure sCMAP
	
	tagCMAP.l
	length.l
	Array RGB.sRGB(#Colors-1)
	
EndStructure
Structure sBMHD
	
	tagBMHD.l
	length.l
	Width.w
	Height.w
	Xorg.w
	Yorg.w
	Planes.b
	Mask.b
	Compression.b
	Pad.b
	Transparency.w
	Aspect.w
	PageW.w
	PageH.w
	
EndStructure
Structure sIFF
	
	tagFORM.l
	length.l
	tagILBM.l
	
	BMHD.sBMHD
	CMAP.sCMAP
	BODY.sBODY
	
EndStructure

Procedure FillStruc(*Stru.sIFF)
	With *Stru
		
		\tagFORM	=	'F'+'O'<<8+'R'<<16+'M'<<24
		\length		=	SizeOf(sIFF)-8
		\tagILBM	=	'I'+'L'<<8+'B'<<16+'M'<<24
		
		\BMHD\tagBMHD	=	'B'+'M'<<8+'H'<<16+'D'<<24
		\BMHD\length	=	SizeOf(sBMHD)-8
		
		\CMAP\tagCMAP	=	'C'+'M'<<8+'A'<<16+'P'<<24
		\CMAP\length	=	SizeOf(sCMAP)-8
		
		\BODY\tagBODY	=	'B'+'O'<<8+'D'<<16+'Y'<<24
		\BODY\length	=	SizeOf(sBODY)-8
		
	EndWith
EndProcedure


test.sIFF
FillStruc(test)
CreateFile(0,	"r:\test")
WriteData(0,	test,	SizeOf(sIFF))
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Structures messed up

Post by STARGÅTE »

WriteData only works with structures which not contain array, list, map or strings.
The data of arrays, lists, maps, and string are not directly inside the space of the structure, they are linked to other spaces.
You your case you have to iterate through all arrays and array elements by yourself,
or you have to use only static arrays like field[size]

Alternatively, you can use InsertXMLStructure() or InsertJSONStructure() to write a whole structure (including arrays, lists, ...) into a file format like XML or JSON.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Diaco
New User
New User
Posts: 2
Joined: Mon Jun 21, 2021 3:06 pm

Re: Structures messed up

Post by Diaco »

Thanks for reply.
Post Reply