MZ VisuStella CommonEventMenu

In my game, I have one of my characters write Journal entries as a quick and easy way to convey large amounts of information to the player, rather than toss out a long cutscene of multiple pages of dialog, and it has the added benefit of being something they can go back and easily reference in the future, as needed, in case they stop playing the game for a while and then want to pick it back up and have no idea who or what they were doing anymore. (I can't be the only person in the world who suffers from this problem with games, am I?)

One nice thing I've found is the VisuStella CommonEventMenu with lets me write each Journal Entry as a separate common event, and then call the menu to display them so the user can select which journal they'd like to read. My question here is, can someone help me with a little javascript to create my menu properly?

In game I have a variable for "0003 Journal Entries Written", which tracks how many entries the character has written in the story so far. In the CommonEventMenu plugin, you specify which events you want to have accessible by the menu, and there's an area there where you can add custom javascript.

// Declare Variables let list = []; // Add Common Event ID's // Return List return list;

What I need is the simple little javascript routine to load event IDs from 3 (the start element of my Journals in the Common Event database) to 2 + "0003 Journal Entries Written" (the variable which tracks how many entries have been written by the character -- note the 2 here, as when we write our first entry, the variable is stored as 1, and we only need to get elements [3] to [3]. No base 0 at work here.).

Is this something that can be done fairly easily? I can already see a workaround which I *could* implement, if necessary, which would focus a lot on IF conditions...

IF "0003 Journal Entries Written" == 1 THEN
setup event with only 1 entry
Exit Processing
END IF
IF "0003 Journal Entries Written" == 2 THEN
setup event with 2 entries
Exit Processing
END IF
IF "0003 Journal Entries Written" == 3 THEN
setup event with 3 entries
Exit Processing
END IF

It's messy, but it doesn't involve any knowledge of JS. I just think there has to be an easier way than the solution I've came up with, and I'm betting it involves that segment where you can add custom JS to the setup...

Unfortunately, I don't know much JS, so I'm just hoping someone here could help me fill in that missing blank for me, before I end up having to go about doing things the long and dirty way. 😉
Yep that should be a fairly simple bit of javascript. I believe this should do the trick:
JavaScript:
let list = [];
// Get how many entries have been written
let journalsWritten = $gameVariables.value(3);

// For each written entry add the event id starting from 3 to  to the list.
for(let eventId = 3; eventId < 3 + journalsWritten; eventId++){
    list.push(eventId);
}

// Return the list of event ids
return list;
Many thanks. I'll test this later tonight and I'll let you know tomorrow if it works properly, or if something somewhere was off. 🙂


EDIT: I finally got a chance to test this. So far, it’s working just as advertised. Many thanks for the assist here. Your solution is sooooo much prettier and more efficient than mine! (And requires a lot less upkeep for future additions/edits, as well!)

Original thread: https://forums.rpgmakerweb.com/threads/visustella-commoneventmenu.137925/