Crash-tan Crash-tan

1.50.3 Patch Release

Crash BASIC 1.50.3 Release Notes

written by Crash-tan

GRIDS THAT SURVIVE BEING SAVED

Here's a quiet one that bit harder than it looked. If you ever saved a 2D array to JSON — a game board, a tile grid, a matrix of anything — with SERIALIZE$ or SAVEJSON, you didn't get your grid back. You got []. An empty pair of brackets where your whole board used to be. And it happened without a single complaint: the save looked like it worked, the file was there, and every cell had silently vanished.

Flat 1D arrays were fine — [1,2,3] saved and loaded exactly as you'd expect. It was only the moment you added a second dimension that the floor gave out. Worse, it spread: an object or array that contained a 2D array lost it too, so a save file with a "board" field inside it came out {"board":[]} with everything gone.

The cause was old code that only ever knew how to walk a 1D array. Handed a 2D one, it asked for element "5" of a grid that only understands "row 2, column 1" — the grid refused every such request, and the serializer quietly wrote nothing.

The fix

A 2D array now saves as a proper nested array — [[1,2],[3,4]] — the same shape any other tool in the world would expect a matrix to be. Three dimensions nest one level deeper, and so on for as many as you've got. Objects and arrays that hold a grid now save the grid in full, not an empty stand-in.

And it round-trips. Load that JSON back with DESERIALIZE$ or LOADJSON and a rectangular grid comes home as a real 2D array — you index it board(row, col), exactly as you saved it. This works both ways across the fence: a matrix exported from another program loads straight into Crash BASIC as a grid, and a grid you save is a matrix any other program can read.

One deliberate nicety for messy real-world data: if the JSON you're loading is ragged — rows of different lengths, the kind of thing that isn't really a matrix — Crash BASIC doesn't force it into a shape it doesn't have. It comes in as an array of arrays instead (indexed data(row)(col)), so nothing is lost or bent to fit.

Nothing to change in your code. If you'd been avoiding saving grids because they came back empty, they don't anymore — and anything you saved going forward is readable everywhere.