Dialogue option randomizer

Hi again! I’m looking for some constructive critique on how to clean this code up/ if there is maybe a simpler way to achieve what I am looking for?

Here’s the mess of code right now:

… And here’s my thinking: The input is the “down” key, or “S”. Before being inputted, it is run through a test to make sure 1. The PC is within range and 2. The other, prior dialogue options have already been run. The randomizer chooses a number and puts it through three filters, set to 1-3. Depending on which number it has chosen, that filter activates a switch which allows the input (“S” key) through to prompt each line of dialogue. After the dialogue is done, a second filter starts the randomizer back up will simultaneously setting the first filter to “4”, which turns that line of dialogue “off” since the randomizer is only 1-3. Finally, a collision with the correct item needed to progress (In this case, a slime jar) turns the entire system off in order to allow the “Success” dialogue.

So, can I clean this up at all?? Is there a simpler way?? Am I overthinking this???

4 Likes

Thinking about how to improve code like this is really good, shows the ability to improve and not be static in skill.

Normally I would say to think about bundling first, but first I’ll say an issue in the code.
You are getting a nonrepeating random number, but there is a better way of doing this.

This is a simplified version because it doesn’t have collecting the jar and whatnot, but it’s the general idea of what you’re trying to achieve.

What’s happening is the Number List is shuffled, meaning [1, 2, 3] are randomly placed inside of it.
Then it is popped. This selects an option in the Router. The Router is then used to select one of the 3 dialogue options.

Accidentally set the filter to 1, it should be 0. Meaning all messages were used.

4 Likes

ahhh yes this is exactly what I was hoping for!!! I kept thinking that the randomizer felt inefficient. Thank you for the tip!! And the compliment :slight_smile:

5 Likes