Yanfly-Common Event Menu:How to remember made choice's position?

Dear fellow makers:

I am currently using Yanfly's Common Event Menu plugin to...eh...set up common event menu for my project.

The plugin is working fine, but there is one problem for my menu that's really bothering me. I been working to sovle this problem for the past few days, and I just found out its beyond my capability.😐

So I really need some help here.

1.png
Above image is a brief introduction for the menu. Basicely when select 'Before select' option, player will be sent to select an item, and then return to the menu, and the option name will be changed to the selected item's name.

2.png
Above image is how I set up the menu.

The problem I am having is, when there are multiple options, after select an item and go back to the menu, the little twinkling selection bar is back to the top of the menu.

3.png

This will not be a problem if there are only a few options, but in my case, I have some menus that contain 30 options. Then it become quite annoying to have to move the twinkling selection bar up and down everytime, after select an item.

To solve this problem, I want to add a function to the menu so it can remenbers the position of the selection bar. Thus, each time after select an item and go back to the menu, the selection bar will stay at where the previous selected option is, instead of going back to the top of the menu.

The concept I'm currectly working on is as follow:

First of all, I created a variable called 'option position'.

4.png
Then I add a content fo control variables to my option's contents page, like above.

Since the postion of all the options are fixed, this will give me an variable that represents the position of the option.

Then, I just have to load the variable and move the selection bar to the represented position each time when after select an item.

But......I don't know how.😢

I have no idea how to move the selection bar!😐

Is there anyone knows how, or have a better method?

Please help!
Bump.

http://yanfly.moe/2016/05/06/yep-98-common-event-menu-rpg-maker-mv/

I add the plugin link above. Anyone? Please?
Bump.😢
I work on a RPG Maker MV Game for about 3 Weeks. Now I've needed exactly what you're looking for 🙂
I researched almost the whole day to figure out, how to save the position of the current pointer in the "Yanfly Common Event Menu"-Plugin. (This really was no easy task, but I did it)

Maybe some of you guys out there want to know how I did it, and I like to share it with you. (And if don't had figured this out, AuralPC, you maybe will get back to your work from one year ago 😉)

At first I reasearched, how I could set the position of the cursor manually.
I looked at every JavaScript-Object, where the Cursor-Position might be is set and I found out, that there are 2 important variables in "SceneManager._scene._commonEventMenuWindow":
  1. SceneManager._scene._commonEventMenuWindow._index
  2. SceneManager._scene._commonEventMenuWindow._cursorRect.y
This is where the Position of the Cursor is storaged.
After that I had to refresh the current windows. There are few refresh/update functions, but the _refreshCursor()-function have to be triggered to update the cursor.

But I had a huge issue to handle: Where should I place this code?
After a bit of testing, I suddenly remembered that there is a way to check if the common event in the Menu-List is disabled or not.
The testing for the activation/deactivation in one of the menu-items is the right place to set the script. I set the script in the first item of my common-menu.

In addition to the cursor-setter, I have stored a index-variable after the player has selected an item.
The index is beginning at '0' (as usual in programming). You really have to know, where your indexes at! (Or maybe you figure out any dynamic way, I haven't thought of 🙂 )
After the Common-Event's work is done, it will save the Variable in the globals and reload the menu. After the reload it will get this Variable and use it for the script.
This Variable will be setted to '0' again, if the player cancel the input. (You don't have to, if you would save the players choice for the next time, the menu pops up).

Now to the step-by-step tutorial:

1. Set the Script in one of your Menu-Items
Spoiler: Main-Script
var cursorID = $gameVariables.value(529);
var window = SceneManager._scene._commonEventMenuWindow;
Spoiler: Main-Script
if( cursorID > 0 ) {
window._index = cursorID;
window._cursorRect.y = cursorID * window._cursorRect.height;
window._refreshCursor();
}


92548-c18a08a48979ce17d58badd9d2415d5c.jpg


Make sure, that the Script is whithin the <Menu Enable Eval>-Section
EDIT: The Code in the above spoiler has to be inserted in the same Comment. I tried to fix this, but I can't.

2. Set the Variable for the right index

Spoiler: Set Variables
upload_2019-4-14_21-36-14.png


You can count the listet menu-items, or you can enter following code in the Dev-Console:
SceneManager._scene._commonEventMenuWindow._index;

3. (Optional) Set the Variable to "0" if the player is canceling the input

Spoiler: Optional
upload_2019-4-14_21-41-28.png


If you don't insert this line of code, the game will remember the players current item-index for the next time.

Remember to always renew the CommonEventMenu if you run any CommonEvent.
I had made an Common Event for that. In every single Menu-Item the player can select, will this event be called. (With exception of the "Cancel"-Button)
Spoiler: Callback
upload_2019-4-14_21-48-50.png


upload_2019-4-14_21-47-38.png

Don't let yourself be confused by the german names of the Common-Events 🙂
I hope you will get the point out of my description 😉

Happy Coding,
Dennis

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-common-event-menu-how-to-remember-made-choices-position.95704/