Here is my take on saving a chessboard. Feel free to use it as a reference:
Code
int w = 8, h =8, scl = 100, sScl = 173, v = 0, sel = -1;
boolean creative = true;
PImage source;
ArrayList<PImage> sprites = new ArrayList<PImage>();
int grid[][] = new int[w][h];
String board = "11,12,0,0,0,0,6,5,10,12,0,0,0,0,6,4,9,12,0,0,0,0,6,3,8,12,0,0,0,0,6,2,7,12,0,0,0,0,6,1,9,12,0,0,0,0,6,3,10,12,0,0,0,0,6,4,11,12,0,0,0,0,6,5";
void setup() {
loadBoard(board);
loadImages();
imageMode(3);
size(800, 800);
}
void draw() {
noStroke();
displayGrid();
}
void displayGrid() {
background(#50c878);
fill(255);
for (int j = 0; j < h; j++) for (int i = j % 2; i < w; i+=2) rect(i*scl, j*scl, scl, scl);
if(!creative) fill(0, 0, 255);
else noFill();
if (!creative && sel != -1) rect((sel % w)*scl, floor(sel/w)*scl,scl,scl);
for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) if (grid[i][j] != 0) image(sprites.get(grid[i][j]-1), (i+0.5)*scl, (j+0.5)*scl);
if (creative) image(sprites.get(v), mouseX, mouseY);
}
String saveBoard() {
String output = "";
for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) output += grid[i][j]+((( (i == w-1 && j == h-1)? "" : ",")));
return output;
}
void loadBoard(String input) {
int info[] = int(split(input, ","));
for (int i = 0; i < info.length; i++) {
int y = i % w, x = floor(i/w);
grid[x][y] = info[i];
}
}
void mousePressed() {
int mx = constrain(floor(map(mouseX, 0, w*scl, 0, w)), 0, w-1), my = constrain(floor(map(mouseY, 0, h*scl, 0, h)), 0, h-1);
if (creative) grid[mx][my] = ((((mouseButton == LEFT)? v+1 : 0)));
else {
if(grid[mx][my] == 0) sel = sel;
else sel = mx+my*w;
}
}
void mouseWheel(MouseEvent e) {
v -= e.getCount();
if (v > sprites.size()-1) v = 0;
if (v < 0) v = sprites.size()-1;
}
void loadImages() {
source = loadImage("sprites.png");
for (int i = 0; i < 12; i++) {
sprites.add(shrink(source.get(i*sScl, 0, sScl, sScl), 0.5));
}
for (int i = 0; i < sprites.size(); i++) {
image(sprites.get(i), i*sScl, 0);
}
}
PImage shrink(PImage input, float value) {
input.resize(floor(input.width*value), floor(input.height*value));
return(input);
}
void keyPressed() {
if (key == ' ') println(saveBoard()+"\n");
else if (key == 'c') {
creative = !creative;
}
}