Use script to get the page number of an event

I want to be able to call a script to find the current page that an event is on, and move it to a variable. Does anyone have any idea how to do this?

If you could write out the script and also include an explanation, that would be extremely helpful. I'm pretty new to some of this scripting stuff, but I have some background in coding, so seeing the code is usually the most helpful way for me to learn stuff about scripting.

Thanks in advance!
what is the reason to know its page number?
On clever way is to make a variable page.
on the beginning of the events/npc's run variable page = Nr
Nr of the page number its on.

but if you can tell for which purpose you need for, coders might be able to help you
on that specific plugin on page number.
NeptuneTron!
The page index is stored in $gameMap.event(id)._pageIndex
$gameMap is the map object, event(id) is a function that returns the event object, and then ._pageIndex is the variable that stores the page number.

So if you want to know the variable of event 1 you want to set a variable to $gameMap.event(1)._pageIndex

But for your purposes we can set a variable to
$gameMap.event(this.eventId())._pageIndex

The most makery way of doing that is using control variables, the operand script and just ploppin' in $gameMap.event(this.eventId())._pageIndex there 😉

You could alternatively use the script call
JavaScript:
$gameVariables.setValue(2, $gameMap.event(this.eventId())._pageIndex)
That sets variable 2 to the event's page number :')

Original thread: https://forums.rpgmakerweb.com/threads/use-script-to-get-the-page-number-of-an-event.119758/