MV Get Actors (even those not in party) biggest level then put it in variable

Is there any way to get Actors (even those not in party) biggest level then put it in variable

Example:
Actor 1: Level - 10
Actor 2: Level - 15
Actor 3: Level - 99
... - 12
... - 10

Variable 1: 99
You can do this without scripting (Control Variables -> Game Data -> Actor -> Level), e.g.
Spoiler: click to see event example
◆Comment:Max level starts = level of actor 1 (Harold) ◆Control Variables:#0010 Level = Level of Harold ◆Comment:Get difference between that and level of actor 2 (Therese) ◆Control Variables:#0010 Level -= Level of Therese ◆If:Level < 0 ◆Comment:Therese's level is higher, so store that ◆Control Variables:#0010 Level = Level of Therese ◆ :Else ◆Comment:Therese's level is equal or lower, so revert to previous value ◆Control Variables:#0010 Level += Level of Therese ◆ :End ◆Comment:Get difference between current max level and level of actor 3 (Marsha) ◆Control Variables:#0010 Level -= Level of Marsha ◆Comment:etc...
...but it's probably more convenient to use Control Variables -> Script:

$gameActors._data.reduce(function(a, c) { return Math.max(a, c.level); }, 0);
Technical details for reduce:
Thank you very much for your reply Caethyril!
Does setting the level as the variable will change the actor to the biggest level?
The options I gave both just get the highest level. No actor's level will change from that.

If you want to change an actor's level, you can use the Change Level event command.
So this is from the editor

Change Party Member: Add Actor 50
Control Variables 119: $gameActors._data.reduce(function(a, c) { return Math.max(a, c.level); }, 0);
Change Level:
RPGMV_XPLklhlBQn.png

But even after this, it stays as their initial level.
Are you using the correct variable? You say
Control Variables 1:

But then you use Variable 119 in your Change Level command.
Hello ATT_Turan! Thank you for helping!
Edited my post and double checked my editor, sadly it's still the same.

Edit:
Is there a script not getting the level but getting the biggest current EXP of all actors? I probably level doesn't work but actors' EXP does.
how do you check the level? If you initialize an actor all data is reset

please give a screenshot of the full event instead of only the one command details - that will show us where you went wrong
It works for me. I'm guessing you've made a mistake somewhere, or maybe it's a plugin issue.

In case it helps, here's how I tested it:
Spoiler: my test event
◆Comment:Get max level across all actors ◆Control Variables:#0010 Level = $gameActors._data.reduce(function(a,c) { return Math.max(a,c.level); }, 0) ◆Text:None, Window, Bottom : :Highest actor level is \v[10]. : :Harold will be set to this level. ◆Comment:Get target - current level ◆Control Variables:#0010 Level -= Level of Harold ◆Comment:Increase Harold's level by that amount ◆Change Level:Harold, + {Level} (Show Level Up) ◆Comment:Check level ◆Control Variables:#0010 Level = Level of Harold ◆Text:None, Window, Bottom : :Level check: Harold is level \v[10].
Hello everyone!
Hakuen Studio from a RPG Maker discord lend a helping hand and this is what worked for me!

const partyLevels = $gameParty.members().map(actor => actor.level)
const actorDataLevels = $dataActors.map(actor => actor ? actor.initialLevel : 0)
const maxLevel = Math.max(...partyLevels, ...actorDataLevels)
$gameVariables.setValue(varid, maxLevel)

Thank you very much @caethyril @ATT_Turan @Andar for the assistance as well!

This thread can be closed.

EDIT: Edited to clarify something based on what @Andar said, sorry about that.
from the official RPG Maker discord
there is no "official" discord and likely never will be due to legal requirements.
that channel is fan-made and not connected to official companies at all, which is why it is not linked here on the forum (and in fact there are rules for not allowing it to be linked here).

as for closing, you need to report the topic for a mod to do that, no mod reads every post.
Ah, I see! If you've never done anything with an actor during a playthrough then $gameActors will not have any data stored for that actor. I forgot about initial levels, thanks for sharing your solution~

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/get-actors-even-those-not-in-party-biggest-level-then-put-it-in-variable.148124/