Quote:So I was wondering, is it bad practice to use operators in an array. I'm thinking for inventories in games it would be handy. Like, using arrayexample$(25+4) and such, where using arrayexample$(29) would not be applicable because you simply wouldn't know it would be 29 or something (so the array would probably be arrayexample$($counter+1). Or is there a more efficient way to tackle this?
Cheers,
Jamie
x
I think that both of the following are considered as bad practice:
DIM array$(25+4)
DIM array$(29)
Looking at either one of these DIMs, I have no clue what 25 or 4 mean, nor what 29 means. They must mean something special because they are defining the size of the array.
Let's say, for example, that 25 means the maximum number of normal entries, and that 4 means the maximum number of overflow entries. Here's how I would code this:
const maxnorm = 25
const maxoflow = 4
DIM array$(1 to (maxnorm + maxoflow))
This will run the same as yours, but it's al lot more understandable. Plus, you can use the constants maxnorm and maxoflow when you need them later in the program, without using the literal constants of 25 and 4 again.
Also, note the DIM array$(1 to ....)
I specifically want to start the array from 1. If you don't code this explicitly, the lower bound of the array will start according to any specified OPTION BASE statement.
*****