Advice for using a range of variables in dialog?

I'm working on a character that has a large amount of interaction prompts, and a reward for people patient enough to stick to the end. I wanted to add more prompts, but instead of adding each variable individually, I've been experimenting with the "greater than"/"less than" conditional branches to see if this is achievable.
I got it semi-working, however it repeats every previous line of dialog, merely adding the next line once the threshold is passed.
I searched and could only find one thread on the topic, but it wasn't much help.
I will share images of my event page if anyone wants to take a look and give advice.

Spoiler: My event page
1.PNG

2.PNG

3.PNG
In the above example you're using both ">" and "=" when you should stick to "=" for a single dialogue.

The ">"s will be true for any number higher than hence all the dialogues with ">" condition show up in order, using "=" should restrict it to a specific number of variable for a specific dialogue.
Your logic is backward.

A good technique to troubleshoot code is to provide an imaginary value and follow it down to see what it does.

If you say your variable 6 is equal to 25, then we follow the chain of logic.
Is it equal to 0? NO

Is it greater than 5? YES, so it will show that

Is it greater than 12? YES, so it will show that

Is it greater than 18? YES, so it will show that

Is it greater than 25? NO, and the same for all further conditionals

So you need to put your checks in descending order and find a way to stop. Either put Exit Event Processing inside each one, or nest them all in Else branches.

Also, some of them look odd with how you've used the operators. For example, when is "is variable > 36" supposed to happen? It won't happen when it is 36 because you used greater than. And it looks like you don't want it to happen when it's 37 or higher because those all have specific responses.

It looks like for at least some of these you mean to be using >=, greater than or equal to.

@BK-tdm That's possible for some of them as I said above, but I don't think it's true for most of them. For example, there's a range of variables from 12 to 18, and I presume that response is what you should be getting for all of them - so > (or >=) is correct. It's just placed backwards.
I just wanted to mention a few things that haven't been mentioned yet:
  • Nothing happens when the variable is between 1 and 5, is that intended?
  • You're using variable #0006 for almost all conditional branches, except for #0001 = 37 (using variable 1 instead of 6). If that's intended, you might want to add a comment, so the next time you go through your event, you know you don't need to "fix" this, because it's working as intended.

Running the code through your head with a random value is a good way to catch some obvious bugs, but sometimes you'll want to run the code multiple times with all possible values. You don't literally need to use every possible value, just the edge cases are enough, such as 0 and 1 (because of = 0), 5 and 6 (because of > 5) and so on. This will allow you to get a map that tells you which value or range of values yield which results:
  • 0:
    Woof

  • 1 - 5: (nothing)

  • 6 - 12:
    Woof Woof

  • 13 - 18:
    Woof Woof (from 6 - 12)
    Bark Bark
Since I'm sure you wouldn't want to reverse your event (since that's a lot of work), the simplest fix would be to invert the conditions instead. That is, instead of > you'd use <= (smaller or equal). However, I get the feeling you actually inteded to use >= (greater or equal), so the correct inversion would be < instead. This would give you the following mapping:
  • 0:
    Woof

  • 1 - 4:
    Woof Woof
    (+ all remaining branches)

  • 5 - 11:
    Bark Bark
    (+ all remaining branches)
To skip the remaining branches, you could use a Label and a Jump to Label. Place the label at the end of the event (before you increment variable #0006), and jump to that label at the end of every conditional branch. Your game will jump to said label and skip all the remaining conditional branches along the way.
Your answer is very thorough, helpful and correct. I just found this personally amusing:
Since I'm sure you wouldn't want to reverse your event (since that's a lot of work)...To skip the remaining branches, you could use a Label and a Jump to Label.
It's more actual keystrokes but certainly the same amount of actual time to cut and paste the conditional branches as it is to add/paste the Jump to Label at the end of each one 😛
There's also an alternative way if you are not scared of using minor scripts - this is personal taste - when you want to check if a Variable is between a and b.

1672172284988.png


Type this:
Code:
5 <= $gameVariables.value(1) && $gameVariables.value(1) <= 8
To check if Variable 1 is larger or equal than 5 and smaller or equal 8.

I would not say that this approach is "better" than the tips from all the people above, it's just a different way. When you don't feel comfortable with typing you can keep going with the <,<=,==,!=,... buttons.
In the above example you're using both ">" and "=" when you should stick to "=" for a single dialogue.

The ">"s will be true for any number higher than hence all the dialogues with ">" condition show up in order, using "=" should restrict it to a specific number of variable for a specific dialogue.
Ah, I had misunderstood how that worked then. Thanks for the input.
Your logic is backward.

A good technique to troubleshoot code is to provide an imaginary value and follow it down to see what it does.

If you say your variable 6 is equal to 25, then we follow the chain of logic.
Is it equal to 0? NO

Is it greater than 5? YES, so it will show that

Is it greater than 12? YES, so it will show that

Is it greater than 18? YES, so it will show that

Is it greater than 25? NO, and the same for all further conditionals

So you need to put your checks in descending order and find a way to stop. Either put Exit Event Processing inside each one, or nest them all in Else branches.

Also, some of them look odd with how you've used the operators. For example, when is "is variable > 36" supposed to happen? It won't happen when it is 36 because you used greater than. And it looks like you don't want it to happen when it's 37 or higher because those all have specific responses.

It looks like for at least some of these you mean to be using >=, greater than or equal to.

@BK-tdm That's possible for some of them as I said above, but I don't think it's true for most of them. For example, there's a range of variables from 12 to 18, and I presume that response is what you should be getting for all of them - so > (or >=) is correct. It's just placed backwards.
That makes so much more sense. I do wonder if this is actually more efficient than manually assigning a line for each interaction, but I'm happy that I actually understand how to do this now.
And yeah, I definitely meant to be using >= for those. I was getting really tired and just experimenting with different things, and missed some lines when I was putting everything back.
I just wanted to mention a few things that haven't been mentioned yet:
  • Nothing happens when the variable is between 1 and 5, is that intended?
  • You're using variable #0006 for almost all conditional branches, except for #0001 = 37 (using variable 1 instead of 6). If that's intended, you might want to add a comment, so the next time you go through your event, you know you don't need to "fix" this, because it's working as intended.

Running the code through your head with a random value is a good way to catch some obvious bugs, but sometimes you'll want to run the code multiple times with all possible values. You don't literally need to use every possible value, just the edge cases are enough, such as 0 and 1 (because of = 0), 5 and 6 (because of > 5) and so on. This will allow you to get a map that tells you which value or range of values yield which results:
  • 0:
    Woof

  • 1 - 5: (nothing)

  • 6 - 12:
    Woof Woof

  • 13 - 18:
    Woof Woof (from 6 - 12)
    Bark Bark
Since I'm sure you wouldn't want to reverse your event (since that's a lot of work), the simplest fix would be to invert the conditions instead. That is, instead of > you'd use <= (smaller or equal). However, I get the feeling you actually inteded to use >= (greater or equal), so the correct inversion would be < instead. This would give you the following mapping:
  • 0:
    Woof

  • 1 - 4:
    Woof Woof
    (+ all remaining branches)

  • 5 - 11:
    Bark Bark
    (+ all remaining branches)
To skip the remaining branches, you could use a Label and a Jump to Label. Place the label at the end of the event (before you increment variable #0006), and jump to that label at the end of every conditional branch. Your game will jump to said label and skip all the remaining conditional branches along the way.
Yeah, a lot of that was just me getting sloppy from being tired. Once I realized I was lost, I had started experimenting with different things, and just missed some stuff when I was putting everything back together to take the screenshots.
I will definitely experiment with the skip you mentioned. That seems like the simplest way. Thanks!
There's also an alternative way if you are not scared of using minor scripts - this is personal taste - when you want to check if a Variable is between a and b.

View attachment 249137

Type this:
Code:
5 <= $gameVariables.value(1) && $gameVariables.value(1) <= 8
To check if Variable 1 is larger or equal than 5 and smaller or equal 8.

I would not say that this approach is "better" than the tips from all the people above, it's just a different way. When you don't feel comfortable with typing you can keep going with the <,<=,==,!=,... buttons.
Thanks for the suggestion. I can kinda see the advantage of that, but I'm a bit hesitant to start experimenting with scripting until I have the basics down. I intend to do similar stuff with other NPCs down the line, so I'll experiment with this later.

Original thread: https://forums.rpgmakerweb.com/threads/advice-for-using-a-range-of-variables-in-dialog.153549/