I have some code as follows. The point is to let the player replay a short game with different possibilities for a final puzzle at the end, so they get all of them, and once they do, the game congratulates them for solving everything.
puzzle-type is a kind of puzzle. The puzzle-types are type-1, type-2, type-3 and type-4. A room has a puzzle-type of endgame-val. puz-list is a list of puzzle-types variable. when play begins: let puz-list be the list of puzzle-types; sort puz-list in random order; puzzle-index is a number that varies. to bump-puzzle-up: increment puzzle-index; if puzzle-index > number of puzzle-types, now puzzle-index is 1; now current-puzzle is entry puzzle-index in puz-list; (place the bad guy in a random room with endgame-val of current-puzzle)
Now this all works and will get me the test cases I want. But for a big test file, I’d like to have the puzzle types lined up in order, as the solution for #2 is different from #1, etc.
Of course, I can create a test command to force a certain puzzle-type at any one time, but if I can get away with just 1 command to say “do things in order,” that’d be nice. Plus I’m genuinely curious about stability.
every turn: say "[the list of puzzle-types]."
Reliably gives puzzles in the same order. So I have these questions:
- is this a reasonable expectation in general? Is this sort of like how table row order is preserved when you sort tables, if two rows have identical values?
- is it bad coding practice to rely on this expectation and, if so, what should I do to make my code work right?
- I see a similar behavior with lists of items. So I’d assume the same answer would apply for items as for values, too?