• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Message choices dependent on conditions

226
Posts
8
Years
  • Age 32
  • Seen Jul 19, 2023
Hello,

I could use some help with this. I can't find a convenient way to use choices that would be dependent on some conditions.

I am trying to create a dialogue in which the visible choices would vary according to the items that the player has in its bag. To put it in another way, having one item should unlock a dialogue feature. If you have Items 1,3 and 7, you will see choices 1,3 and 7, and so on.

Using the \ch[] command would take considerable amount of time to write down all choices one by one by using conditional branches (it means something like 10*9*8... possibilities).

Does someone know a way to make an option visible under specific conditions only?

I apologize if this question is too RMXP-related for the forum. Thanks in advance.
 
119
Posts
10
Years
  • Seen Sep 1, 2023
This is actually not standard functionality of RMXP (using only the standard functions available in events). This can be done by scripts inside an event to construct our own string, which will be the \ch[] command.

First add the following code in a script block;
This creates the start of the \ch[] command, and sets up a way for us to retrieve the correct choice.The 1, 2, and 3 in red are the numbers of global variables used. 3 will eventually store our outcome. Note that if you change these, you will have to chance them in all the script blocks below as well
Code:
$game_variables[[COLOR="Red"]1[/COLOR]]="\\ch[[COLOR="red"]3[/COLOR],-1"
$game_variables[[COLOR="Red"]2[/COLOR]]=[]

Then add in several conditional branches, each being the condition of whether a choice should be visible (put them below each other, without the handling if the condition doesn't apply). Then add the following code in a script block inside the condition branch:
This way we add the desired option to the choices and set up a way to retrieve having selected this choice. The number in pink is the number which will be used for this choice in the end. Thus make sure these are unique for each choice.
Code:
$game_variables[[COLOR="Red"]1[/COLOR]]=$game_variables[1] + ",choice 1"
$game_variables[[COLOR="red"]2[/COLOR]].push([COLOR="Magenta"]1[/COLOR])

After having done this for all possible choices we want to close the \ch[] command and add a cancel option. To do this add the follow code in a script block:
For cancel we want to use a 0 as this way it's easier to add more options later on.
Code:
$game_variables[[COLOR="red"]1[/COLOR]]=$game_variables[1] + ",cancel]"
$game_variables[[COLOR="red"]2[/COLOR]].push([COLOR="Magenta"]0[/COLOR])

Then you add a text message with whatever text you want it to say. At the end, where you want it to show the choice, you add \v[1].

Now that we're showing the correct choices there's one more thing to do; we have to convert to selected choice to the actual number linked to the choice. To do this add a condition branch which checks if the result is larger or equal to 0 (this is necessary to still make the cancelling by pressing B work). Inside the branch add a script block with the following code:
Code:
$game_variables[[COLOR="red"]3[/COLOR]]=$game_variables[[COLOR="Red"]2[/COLOR]][$game_variables[[COLOR="red"]3[/COLOR]]]

After this you can add the conditional branches for each selected option as if you would for a normal \ch[] command.
The end result would look something like this:
conditional%20choices%20example.jpg
 
226
Posts
8
Years
  • Age 32
  • Seen Jul 19, 2023
Wow, your solution is very well explained and it works perfectly. I wouldn't have been able to find this on my own.

Thank you very much for spending some time on this!
 
Back
Top