MV Run an event when choice is highlight? (Solved)

Well as the title says I want to run an event when an choice is highlighted. Like this video I made:


As you can see when an choice is indicated, the object in question is also indicated. The problem is that it's a parallel event that checks if you pressed up or down, but when the buttons are pressed too fast it goes crazy and ends up anywhere. :rsad:
Is there a plugin to make this more accurate?
It depends on how you are drawing those choices.

If it's a standard choice window (e.g. Window_ChoiceList), then Window_Selectable has an index function that will return the index of the currently selected item that you could check via a conditional branch script:

JavaScript:
// Do something if the 2nd item in the list is selected
SceneManager._scene._messageWindow._choiceWindow.index() === 1

If those choices are pictures drawn on the screen with Show Picture or something similar, then I'm not sure. I haven't done much eventing myself.
It depends on how you are drawing those choices.

If it's a standard choice window (e.g. Window_ChoiceList), then Window_Selectable has an index function that will return the index of the currently selected item that you could check via a conditional branch script:

JavaScript:
// Do something if the 2nd item in the list is selected
SceneManager._scene._messageWindow._choiceWindow.index() === 1

If those choices are pictures drawn on the screen with Show Picture or something similar, then I'm not sure. I haven't done much eventing myself.

They are normal choice window, it's just a plugin that makes them look like that.

I don't understand how to use the code. can you give me a small example?
If it's not too much trouble. 😅
Use the 'script' box of a Conditional Branch event like so:

RPGMV_9BAqE8cWNQ.png


Replace the 'flash screen' event with whatever it is you want to actually event. Note that 0 would be the first item in the list, 1 would be the 2nd, etc.

Just be aware that if you run this in a parallel process, the condition will repeatedly be met for as long as the item is selected, so you need to set up your events in a way to ensure the triggered event only runs once and not over and over again. Maybe with a switch?

I have very little eventing knowledge, so I'm sorry that I don't have any ideas for how to handle that. 😅
Wow, it's so much easier now. 😂 I just have to see how I solve the fact that the event repeats itself. Thank you for the answer! I'm sure it will be useful for many things.

I will comment when I solve it, in case someone else wants to do something like this.
Use the 'script' box of a Conditional Branch event like so:

View attachment 224942

Replace the 'flash screen' event with whatever it is you want to actually event. Note that 0 would be the first item in the list, 1 would be the 2nd, etc.

Just be aware that if you run this in a parallel process, the condition will repeatedly be met for as long as the item is selected, so you need to set up your events in a way to ensure the triggered event only runs once and not over and over again. Maybe with a switch?

I have very little eventing knowledge, so I'm sorry that I don't have any ideas for how to handle that. 😅
I just have to see how I solve the fact that the event repeats itself

Something as simple as this in your event should work for you:

RPGMV_3aLG6UTBX7.png


Replace the "Script: console.log" event with the event commands that you want to run, but keep the other script call in there at the end.

You would need a very simple plugin for this to work, as follows:

JavaScript:
Window_ChoiceList.prototype.select = function(index) {
    Window_Command.prototype.select.call(this, index);
    this._eventRan = false;
}
@Kenen Oh noo, it clashes with several plugins, or did i write something wrong? I'm kind of dyslexic...

1651537570894.png

1651537454973.png

1651537510927.png

I add the plugin too

1651537779964.png
@Kato-A Take a look at this screenshot:

1651537510927_edit.png


You could also change the condition of your conditional branch to a game switch being turned off (e.g. game switch #1) and then turn that switch on inside the condition, if you think that might be less prone to error.

I could update the plugin to flip a switch instead of changing the variable. Let me know what you think.
My mistake 😅 It works just fine now! No need to make any change.
Thank you so much!! 😂 You will be in my credits.
@Kato-A You’re welcome!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/run-an-event-when-choice-is-highlight-solved.147262/