Page 1 of 1
					
				Confused about some syntax
				Posted: Fri Dec 05, 2003 10:51 pm
				by Akuma no Houkon
				Why doesnt the following work, is it not supported or am I doing something wrong. 
Code: Select all
Structure Bob
   One.b
   Two.b
   Three.b
   Four.b
EndStructure
Structure Fred
   AllBobs(10,10).Bob
EndStructure
I am still not used to some of the syntax that PureBasic uses
 
			 
			
					
				
				Posted: Fri Dec 05, 2003 11:12 pm
				by Saboteur
				You can't declare an array into a structure. Arrays are global, and must be declared with Dim.
 
			 
			
					
				
				Posted: Fri Dec 05, 2003 11:29 pm
				by Pupil
				arrays inside structures are static, so you can't redim them later and as far as i know only one-dimensional arrays are supported. so your stucture would translate to something like this:
Code: Select all
Structure Bob
   One.b
   Two.b
   Three.b
   Four.b
EndStructure
Structure InterMidiateFred
   Bob2.Bob[10]
EndStructure
Structure Fred
  Bob1.InterMidiateFred[10]
EndStructure
a.Fred
a[1]\Bob2[1]\One ; example of accessing one item in structure
Oh, and in structures you actually get the amount of items you set inside the brackets not the set value plus one, like you do when using 'Dim'.
 
			 
			
					
				
				Posted: Mon Dec 08, 2003 9:59 pm
				by Akuma no Houkon
				Well what I have is the following:
I have an array of 2d arrays...images would be the easiest reference.  say I have a 32x32 icon, I have 50 of these, and I want to store the pixel information so I can access it via:
Icon(#)\Pixel(x,y)\Red
What would be the easiest way to accomplish this within the PureBasic structure?
The "images" are always a fixed size, and always the same size.
I "might" be able to restructure my system to use a 1d array of longs rather than a 2d array of bytes, but that would not be the ideal situation given the choice.
			 
			
					
				
				Posted: Mon Dec 08, 2003 11:52 pm
				by freedimension
				Code: Select all
Structure Rows
  Y.l[50]
EndStructure
Structure Icon
  X.Rows[50]
EndStructure
a.Icon
a\X[20]\Y[30] = $FF00FF
If it's not speed you're interested in (i.e. it doesn't matter) you can sort of simplify it by simply creating procedures. This enhances human readability a little bit.
Code: Select all
Procedure GetIconPixel(*a.Icon, x, y)
  ProcedureReturn *a\X[x]\Y[x]
EndProcedure
Procedure SetIconPixel(*a.Icon, x, y, value)
  *a\X[x]\Y[y] = value
EndProcedure
SetIconPixel(*a, 20, 30, $FF00FF)
GetIconPixel(*a, 20, 20) ; would return $FF00FF