• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Issues with storing Hex Colours in an array

PixelMochii

Member
Hiya, I'm attempting to store a bunch of hex colours into a 2d array so that I can access them later to randomise colour schemes, but using the $ symbol in my array returns an invalid syntax error. Does anyone know how to store colours in this form without gamemaker hating it?

the 2D array I want to create:
Code:
ranCol = 
[
    [$FFFFFF, $FF99FF, $7F4810, $4C0002, $2D130D, $000000],
    [$E2DDFD, $95A0FA, $CBD99F, $798B02, $994C2D, $991E38],
    [$FFFFFF, $FF99FF, $7F4810, $4C0002, $2D130D, $000000],
    [$E2DDFD, $95A0FA, $CBD99F, $798B02, $994C2D, $991E38],
    [$FFFFFF, $FF99FF, $7F4810, $4C0002, $2D130D, $000000],
];
Error:
Code:
Object: oCellAuto Event: Create at line 7 : unexpected symbol "[$" in expression
 

Amon

Member
Why not just store the numbers, then when a random is retrieved append the '$' sign to the beginning of it using the string commands and plop the result into a new string?
 

chamaeleon

Member
I'm going to guess the parser is interpreting $ as the struct accessor which is not correct in this context. Switch to using 0x instead.
GML:
ranCol =
[
    [0xFFFFFF, 0xFF99FF, 0x7F4810, 0x4C0002, 0x2D130D, 0x000000],
    [0xE2DDFD, 0x95A0FA, 0xCBD99F, 0x798B02, 0x994C2D, 0x991E38],
    [0xFFFFFF, 0xFF99FF, 0x7F4810, 0x4C0002, 0x2D130D, 0x000000],
    [0xE2DDFD, 0x95A0FA, 0xCBD99F, 0x798B02, 0x994C2D, 0x991E38],
    [0xFFFFFF, 0xFF99FF, 0x7F4810, 0x4C0002, 0x2D130D, 0x000000],
];
 
Why not just store the numbers, then when a random is retrieved append the '$' sign to the beginning of it using the string commands and plop the result into a new string?
I don't think a string would function in the same way as the actual hex number when it comes to assigning colours.
 
Top