The Let's Play Archive

Compute!'s Gazette

by Chokes McGee

Part 40: Hex Wars: An autopsy (Part 4)

Hex War: An Autopsy: Part 4

Last time, all we did is get ready to play a tone. It just took a while to explain how. Can we do better this time? Let's find out.
code:
30 DIM J, K, HT, HB, CT, CB, J1, J2, A, B, C, D, E
40 DIM ARMY(31, 6, 1), BTL(64, 1, 3), MAP(9, 9, 2), FQ(20, 1), NX(1), C(2)
50 CN = 12:DIM CIT(CN, 1)
Lines 30-50 make extensive use of the DIM command. DIM is used to create an array, which is a set of variables referenced by a common name and one or more values. Arrays are zero-indexed, which means that any integer from 0 to the maximum size of a dimension is a legal value for an element of the array. Arrays can be integer arrays, string arrays, or floating point arrays, depending on the extension (if any) before the list of dimensions; in this case, all of our arrays are floating point arrays (the default). Floating point arrays and integer arrays are initialized to have all of their elements be 0; string arrays are initialized to have all of their elements be "" (an empty string). Only one array of a given type and name can exist; if you try to create another, even if it has different dimensions, your program will crash.

Line 30 is a bit odd, in that it DIMs non-array variables. This is technically legal (even if some references say otherwise), but pointless, as ordinary variables are created and initialized when you first use them. (About the only reason I can think of to do this is if memory's tight and you want to make sure your program won't crash when it tries to use the variables later.) Incidentally, you don't have to DIM arrays either, as long as you want a single-dimensioned array with 11 elements (0-10). As you can see, though, all of the arrays defined here have a different size.

So what are all these variables? Well, in order of definition:
That's a fair whack of information, and it represents a fair whack of research, figuring out what all those variables were used for. With that in mind, and with me wanting to type in another game, I'll leave off here. Next time, we'll stick values in a bunch of stuff!