Confused about some syntax

Just starting out? Need help? Post your questions and find answers here.
Akuma no Houkon
User
User
Posts: 77
Joined: Sun Nov 02, 2003 1:47 pm
Location: Washington
Contact:

Confused about some syntax

Post 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
AMD 2600+, nVidia Geforce FX 5200 128 MB DDR, 512 DDR, RedHat 9
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

You can't declare an array into a structure. Arrays are global, and must be declared with Dim.

Code: Select all

Dim AllBobs.Bob(10,10)
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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'.
Akuma no Houkon
User
User
Posts: 77
Joined: Sun Nov 02, 2003 1:47 pm
Location: Washington
Contact:

Post 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.
AMD 2600+, nVidia Geforce FX 5200 128 MB DDR, 512 DDR, RedHat 9
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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
Post Reply