On hover over choice - activate switch

Hi,
I am currently using Galv Choice Pictures but I need a bit more functionality I'm not finding anywhere. Any suggestions on how to make a switch activate when you hover over each choice? Maybe a script call?

1. Choice A - Switch 123 activates
2. Choice B - Switch 456 activates
3 Choice C - Switch 789 activates

Thank you!

I've moved this thread to Javascript/Plugin Support. Thank you.

Hi!
You can try to use a script call to access the index of each choice in a parallel event.
SceneManager._scene._messageWindow._choiceWindow._index
This should give you the index of the currently highlighted choice.
So you use a condition, if index === 1 activate switch X.

OBS: I do not sure if this is the right script call to get the index, I'm not on computer right now. Maybe it has some typo on it, I have to check tomorrow.

NOTE2: Also, I don't remember if choice1 = index1
Or choice1 = index0

You can try these in the console if you know how to use it ^^
Choice 1 is definetly index = 0.
I checked the call script, it works, no typos 🙂
I'm not sure how to use this info.
I'm not sure how to use this info.

If you want to activate a switch under the condition of the choice window, then it should look something like this.

If this still doesn't help, then I need to see some screenshots of your choice window and the script behind it.
I found none of this or anything else online helpful. I don't really know how to write javascript but I bumbled my way through enough and found enough pointers on smaller aspects that are used to do this. The BIGGEST resource that helped me achieve this is Google Doc - RPG Maker MV/MZ Javascript calls
Heres the code I used:


document.addEventListener('mousemove', getMousePosition);
document.addEventListener('mouseenter', getMousePosition);
function getMousePosition(e) {
var x = e.pageX;
var y = e.pageY;
if ($gameSwitches.value(5)) {} else {
if ((x >= 700 && x <=795) && (y >= 306 && y <= 339)) {
$gameScreen.showPicture(1, 'Actor1_1', 0, 256, 95, 100, 100, 255, 0);}
else {
if ((x >= 700 && x <=795) && (y >= 346 && y <= 384)) {
$gameScreen.showPicture(1, 'Actor1_2', 0, 256, 95, 100, 100, 255, 0);}
else {
if ((x >= 700 && x <=795) && (y >= 391 && y <= 424)) {
$gameScreen.showPicture(1, 'Actor1_3', 0, 256, 95, 100, 100, 255, 0);}
else{$gameScreen.erasePicture(1)}}}}}


(My code is set up for a 3 choice option set to the right side of screen. you can change for more choices or different screen position by changing x y coordinates and adding additional if else statements.)
Basically,
1) tell the game to start listening to mouse coordinates
3) set an if else statement to see if in game switch #5 is on or off. (if on do nothing, if off continue on to the next set of if statements)
4) set if else statements to check if the mouse x and y coordinates are within a certain range (have the x-y ranges match where the choices are displaying)
3) set the pictures you want, where you want them.

The switch check I have found necessary. if I dont have it check for that switch then as soon as this script runs, no matter what map you are on, even if the event that ran this script is erased, hovering in the spot where the choices are will display the pictures.
It is worth noting that this only displays pictures on MOUSE HOVER, so choosing options with arrow keys wont show the pictures. I doubt this will help you being 2 years later, but hopefully it helps someone else, because I spent most of a day focused on both building this and trying to get the pictures to not show when the choices are gone.

if you need to find out the mouse coordinates for your choices, make an event that first has the below code, then displays the number of choices where you want them, then has a text box output to show your coordinates.


document.addEventListener('mousemove', getMousePosition);
document.addEventListener('mouseenter', getMousePosition);
function getMousePosition(e) {
var x = e.pageX;
var y = e.pageY;

$gameVariables.setValue(1, x)
$gameVariables.setValue(2, y)
}


Make the text box output something like
"Your X coordinate = \V[1]
Your Y coordinate = \V[2]"
This might be necro, but I had trouble accessing an hovered choice index as specified in the previous posts.
This is the code I used to retrieve it inside a game variable, on MZ:

Code:
SceneManager._scene._choiceListWindow._index
This might be necro, but I had trouble accessing an hovered choice index as specified in the previous posts.
This is the code I used to retrieve it inside a game variable, on MZ:

Code:
SceneManager._scene._choiceListWindow._index
It's because MV and MZ code are different.

For MV:
SceneManager._scene._messageWindow._choiceWindow._index

For MZ
SceneManager._scene._choiceListWindow._index

Original thread: https://forums.rpgmakerweb.com/threads/on-hover-over-choice-activate-switch.123126/