Author Topic: Type As Array  (Read 733 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Atari ST
  • *******
  • Posts: 237
  • Karma: 12
  • Computers have lots of memory but no imagination
    • View Profile
Type As Array
« on: July 06, 2011 »


Hi guys any one know whats wrong with this?  :-\ It's in BlitzMax

Type RGBQUAD
    Field rgbBlue:Byte
    Field rgbGreen:Byte
    Field rgbRed:Byte
    Field rgbReserved:Byte
End Type

Global bmiColors:RGBQUAD = New RGBQUAD[255]

This is how I would use it: bmiColors[a].rgbBlue = 10
Just can't see the trees for the wood.
Thanks

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Type As Array
« Reply #1 on: July 06, 2011 »
far as I know....this one should work

Code: [Select]
Type RGBQUAD
    Field rgbBlue:Byte
    Field rgbGreen:Byte
    Field rgbRed:Byte
    Field rgbReserved:Byte
End Type

Global bmiColors:RGBQUAD = New RGBQUAD

But what you trying to do is doing Type with Arrays?

I am not sure if that what you want

Code: [Select]
Type RGBQUAD
    Field rgbBlue:Byte[255]
    Field rgbGreen:Byte[255]
    Field rgbRed:Byte[255]
    Field rgbReserved:Byte[255]
End Type

Global bmiColors:RGBQUAD = New RGBQUAD


Offline Pot Noodle

  • Sponsor
  • Atari ST
  • *******
  • Posts: 237
  • Karma: 12
  • Computers have lots of memory but no imagination
    • View Profile
Re: Type As Array
« Reply #2 on: July 06, 2011 »
I have tryed that, I just get an error "bmicolors can't be Indexed"  :telloff:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5243
  • Karma: 393
    • View Profile
Re: Type As Array
« Reply #3 on: July 07, 2011 »
yeah, that would give you
Code: [Select]
bmiColors.rgbBlue[0]
to
bmiColors.rgbBlue[255]

You want
Code: [Select]
Type RGBQUAD
    Field rgbBlue:Byte
    Field rgbGreen:Byte
    Field rgbRed:Byte
    Field rgbReserved:Byte
End Type

Global bmiColors:RGBQUAD[] = New RGBQUAD[256]
note the extra pair of square brackets after RGBQUAD.  There are 256 entries in the palette, not 255.
You could also do
Code: [Select]
Global bmiColors:RGBQUAD[256]

Jim
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Atari ST
  • *******
  • Posts: 237
  • Karma: 12
  • Computers have lots of memory but no imagination
    • View Profile
Re: Type As Array
« Reply #4 on: July 07, 2011 »
Thanks Jim, Brill, them Blitzmax arrays do my head in.  :goodpost:

Unhandled Exception:Attempt to access field or method of Null object

on this line:
For a = 1 To 127
        bmiColors[a].rgbGreen = 255 - 2 * a <----- Error
        bmiColors[a].rgbRed = 2 * a
    Next
« Last Edit: July 07, 2011 by Pot Noodle »

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5243
  • Karma: 393
    • View Profile
Re: Type As Array
« Reply #5 on: July 08, 2011 »
OK, so each of those array slots is just a 'pointer' to an RGBQUAD, you need to allocate some space for the data.
Code: [Select]
For a = 1 To 127
  bmiColors[a] = New RGBQUAD
  bmiColors[a].rgbGreen = 255 - 2 * a
  bmiColors[a].rgbRed = 2 * a
Next
I'm not sure if it's necessary to do that if you used
Code: [Select]
Global bmiColors:RGBQUAD[] = New RGBQUAD[256]
Not sure.  I've never used BlitzMax.

Jim
Challenge Trophies Won: