#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# need help organizing data (Sugarcube 2.6)

Hey everybody,

I wrote a little quiz game, which I am not unsatisfied with. I have my passages, which hold the quiz questions, organized like this:
```0x0 0x1 0x2 0x3 0x4 0x5 0x6 etc.
1x0 1x1 1x2 1x3 1x4 1x5 1x6 etc.
2x0 2x1 2x2 2x3 2x4 2x5 2x6 etc.
3x0 3x1 3x2 3x3 3x4 3x5 3x6 etc.
4x0 4x1 4x2 4x3 4x4 4x5 4x6 etc.
```

The first digit (before the "x") marks the difficulty level, the third digit (after the "x") marks the round. So, as players answer their questions right or wrong, they move up and down the difficulty range, whereas the round value automatically increments after each round.

So far so good. But after playing several rounds I found the static approach (that you move automatically from e.g. round 4 to round 5) hinders replayability, because a player will mostly repeat the same questions.

This is why I want to randomize the question path, meaning that the game automatically chooses the next passage from a pool of existing round numbers. So I could just go and
```<<set \$rounds to [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21]>>
```

pick one element as the next passage destination, remove it from the array and so on...

BUT:

My questions are follow-up-questions, they are organized in groups of three, e.g. questions 0 through 2 cover one topic, question 3 though 5 the next, 6 through 8 ....

So randomly jumping from one question to another would mess up these blocks of questions.

How could I organize the questions in blocks? Let's say random picks 9, which means the player gets questions 9,10 and 11 and then the next question block is picked by random again.

richVIE

ps. Is there maybe a solution which allows me to define blocks of different lengths?

• The easiest thing would probably be to use nested arrays to categorize your questions. For example:
```<<set \$categories to [
[ 0,  1,  2],
[ 3,  4,  5],
[ 6,  7,  8],
[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17],
[18, 19, 20],
[21, 22, 23]
]>>
```
You should get the idea.

From there you'd randomly pick a category. Assuming categories shouldn't repeat, I'd suggest using the <Array>.pluck() method. For example:
```<<set \$round to \$categories.pluck()>>
```
That will yield an array of round IDs, which you could handle in whatever manner you'd preferâ€”either randomly or in a specific order.