PDA

View Full Version : 2d array only acting like a flat array




jaybee2002
May 25, 2011, 09:04 AM
ok here is m problem,
i have a game which is using a 2d array to load up what the user has done previously (saving state) for each level, to do this i am using a 2d array.
at the moment i have 5 levels and 36 values so save for each level so im using-
gameState[5][36];

and when on the level im loading using,

for (i=1; i<=36; i++)
{
squarepic[i] = gameState[level][i];
}

and the oposite way round to save the game stat for the level.

my problem arrises when i try and change between levels and the array seems to treat each level like they are the same so whatever has happened in level 1 moves over to level 2 and level 3 as if they were all the same level.

anyone any idea why this could be happening.

thanks jon



Hansr
May 25, 2011, 09:23 AM
Post the actual saving and loading code.

seepel
Jun 4, 2011, 06:34 PM
Sounds like a simple logic error, where maybe you level variable isn't getting set correctly, so you end up accessing the same level rather than different ones? (P.S. 2D arrays are actually flat arrays... in memory at least. When I read the title I just had to mention it.)