MV Can I use a Formula inside of a plugin's parameters instead of just a number? (Trying to Access Screen Width and Screen Height)

What I ultimately want to do is have a HUD with ModHunter's plugins (Lets use ActorHUD in this example) that gets repositioned when a different screen resolution is chosen by the player using MUSH's OptionSystemPlus_P2 plugin.

My question is instead of just putting the HUD a certain amount of pixels somewhere on the screen, can I use a Formula to put it like...

Code:
x = screenWidth/2 - hudLength/2
&
y = screenHeight - hudHeight

...to put the hud at the bottom center, no matter what the resolution is instead of just putting in numbers, like
Code:
x = 0
&
y = 440


I was looking around and the closest thing I found to something like this is
Code:
var gw = Graphics.width;
var gh = Graphics.height;
from here (https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-screen-size.58660/)


I'm just curious if there anything in the API, like screenWidth or screenHeight, I really don't want to use hard numbers if I can help it, especially since I want to give the option for multiple resolutions.


Looking through the API I see this...



I tried putting this in ActorHUD's
Code:
y = (Scene_Map.height/2)
Just made it disappear.



Anyone know how to do this or if its possible?
Scene_Map is a type, not an instance of a scene
The current scene can be accessed at SceneManager._scene but what you actually want for screen res is Graphics.boxWidth and Graphics.boxHeight
Not sure if the plugin param in question actually takes a formula but you can just check the plugin parameters handling in the code and see if it's expecting a value or a function
you can just check the plugin parameters handling in the code and see if it's expecting a value or a function
Do that first, but most likely it will just expect numbers, so you'd need to modify the plugin's code and replace the parameters with your formula.
Hi!
It's not just the plugin parameter that must accept text(formula). But also the plugin code that need to parse the parameter as a formula.

If it accepts, probably the plugin author will let you know on the help file or parameter description.
If it accepts, probably the plugin author will let you know on the help file or parameter description.
This. Unless the author says otherwise in the documentation, you should assume that all plugin parameters (and plugin command arguments, etc.) can only take the exact kind of value described.
Even if the parameter accepts a formula, there is a chance that the formula is only read and evaluated one time (when the game first boots up), so it still might not work the way that you're hoping. The plugin would likely need to be edited to account for dynamic resolution changes.

what you actually want for screen res is Graphics.boxWidth and Graphics.boxHeight
The screen resolution is actually determined with Graphics.width and Graphics.height. The "box" variants give you the dimensions of the window layer instead. Which one you'd want to use depends on whether the HUD is added directly to the scene (i.e. this.addChild) or to the window layer (i.e. this.addWindow).
Ah, thanks for the replies. So it doesn't accept formulas so I looked into the code...


This is what the plugin is doing:


Spoiler: Tracking the x and y params inside MogHunter's ActorHUD
Code:
* @param Hud X-Axis
 * @desc Setting the Hud's X-Axis position.
 * @default 0
 *
 * @param Hud Y-Axis
 * @desc Setting the Hud's Y-Axis position.
 * @default 440

// HUD POSITION
    Moghunter.ahud_pos_x = Number(Moghunter.parameters['Hud X-Axis']);
    Moghunter.ahud_pos_y = Number(Moghunter.parameters['Hud Y-Axis']);

//==============================
// * Set Hud Position
//==============================
Actor_Hud.prototype.set_hud_position = function() {
     this._hud_size[0] = Moghunter.ahud_pos_x - ($gameMap.tileWidth() / 2);
     this._hud_size[1] = Moghunter.ahud_pos_y - ($gameMap.tileHeight() / 2);
     this._hud_size[2] = Moghunter.ahud_pos_x + this._layout.bitmap.width - $gameMap.tileWidth();
     this._hud_size[3] = Moghunter.ahud_pos_y + this._layout.bitmap.height;    
     this._pos_x = Moghunter.ahud_pos_x;
     this._pos_y = Moghunter.ahud_pos_y;
};

//==============================
// * Need Fade
//==============================
Actor_Hud.prototype.needFade = function() {
    if (this._hud_size[0] === -1) {return false};
    if (!this._battler) {return false};
    if (!$gameSystem._ahud_smartFade) {return false};
    if ($gamePlayer.screen_realX() < this._hud_size[0]) {return false};
    if ($gamePlayer.screen_realX() > this._hud_size[2]) {return false};
    if ($gamePlayer.screen_realY() < this._hud_size[1]) {return false};
    if ($gamePlayer.screen_realY() > this._hud_size[3]) {return false};   
    return true;
};

//==============================
// * Refresh Position
//==============================
Actor_Hud.prototype.refresh_position = function() {
     this.set_hud_position();    
     this.visible = true;    
     this.create_sprites();
      this._layout.x = this._pos_x;
     this._layout.y = this._pos_y;
     if (this._face) {
          this._face.x = this._pos_x + Moghunter.ahud_face_pos_x;
          this._face.y = this._pos_y + Moghunter.ahud_face_pos_y;
         this._battler._face_pos = [this._face.x,this._face.y];
     };
};

I'm not sure how to read $gameMap, I've tried searching it up but nothing I'm finding on it is useful...



Quest to find out exactly what $gameMap is​

Spoiler: Tracking down the details of $gameMap
I'm going to document this because it was hard for me to find direct information on it, hoping its helpful.

Looked here: How does the $gameMap.data array work?

The API for $gameMap tells me its defined in the file rpg_managers.js, so I search in RPGMV's folder for it and it takes me to the file located in KADOKAWA\RPGMV\NewData\js.

I only found this in that file...
Code:
function DataManager() {
    throw new Error('This is a static class');
}

var $gameMap          = null;

DataManager.createGameObjects = function() {
    $gameMap           = new Game_Map();
};

DataManager.makeSaveContents = function() {
    contents.map          = $gameMap;
};

DataManager.extractSaveContents = function(contents) {
    $gameMap           = contents.map;
};


Decided to look at all the js scripts in the folder...
133 Results in rpg_objects.js
45 hits in rpg_sprites.js
8 hits in rpg_scenes.js
3 hits in rpg_windows.js



It looks like rpg_objects has all of $gameMap's parameters, for instance...


Code:
Game_Map.prototype.tileWidth = function() {
    return 48;
};


Game_Map.prototype.tileHeight = function() {
    return 48;
};

So...
$gameMap.tileWidth() = 48
&
$gameMap.tileHeight() = 48


Here are the width and height mentioned above (I think?):
Code:
Game_Map.prototype.width = function() {
    return $dataMap.width;
};
Game_Map.prototype.height = function() {
    return $dataMap.height;
};


It turns out I didn't need $gameMap, but I'll still post this because I would have liked to have something to find like this explaining where everything is with that $/jQuery.


Graphics.width & Graphics.height worked thanks everyone!

Code:
Actor_Hud.prototype.set_hud_position = function() {
     this._pos_x = (Graphics.width / Moghunter.ahud_pos_x);
     this._pos_y = (Graphics.height / Moghunter.ahud_pos_y);
};



EDIT:
Just wanted to say, Graphics.boxWidth & Graphics.boxHeight also worked here

Code:
Actor_Hud.prototype.set_hud_position = function() {
     this._pos_x = (Graphics.boxWidth / Moghunter.ahud_pos_x);
     this._pos_y = (Graphics.boxHeight / Moghunter.ahud_pos_y);
};
It's not clear what your JavaScript knowledge/skill level is, so I'm not sure how in-depth you want anyone to go with an answer.

A lot of it is explained right on the page you already linked to:
1707853953320.png


$gameMap is a global variable of the type Game_Map - just as you see the declaration of it here:
Code:
DataManager.createGameObjects = function() {
    $gameMap           = new Game_Map();
};

So...what is your outstanding question?
There is no question, I just included that because I thought it could be helpful for someone else who goes looking for details to know exactly where all that stuff for $gameMap was.

I wrote some JavaScript before but never used any frameworks, including jQuery (Didn't know that $ meant jQuery either) so not being able to just go to the declaration of the code so I could see what it was doing was confusing to me is all.

Everything I needed to know about $gameMap's and its parameters/functions was hidden away in rpg_objects.js, but I couldn't find anywhere on the internet that told me that. I had to manually look for it - so I put it in the post... so it'd be on the internet.
I wrote some JavaScript before but never used any frameworks, including jQuery (Didn't know that $ meant jQuery either)
It doesn't.

RPG Maker's programmers chose to use the prefix character $ for all global variables. It's just a part of the name, it doesn't have any syntactic meaning.

It has nothing to do with the jQuery library, which uses a different syntax - $(selector).action()

You'll note there are no parentheses around (gameMap) after the dollar sign.

Everything I needed to know about $gameMap's and its parameters/functions was hidden away in rpg_objects.js, but I couldn't find anywhere on the internet that told me that.
On the page you linked to, if you clicked on the hyperlink for the Game_Map type (or looked for it on the side bar), it takes you to a page that fully lists all properties and methods of that type.


Each of those, in turn, tells you which file they're declared in:
1707855710946.png
Ah, thanks for the clarification on $, I thought that's what it might have been since I couldn't just go to it with Go To Definition in Visual Code. Reason I thought this was this page. Specifically this line "In fact, $ is just a shortcut for jQuery."


I just got a 404 Page not found when I clicked on the link on the API page's link.


Its funny, for some reason I didn't see that blue link above it. Opps. Not sure why I just kept looking past that. My bad. Anyway thanks for pointing that out hah, can't believe I didn't see it.
Ah, thanks for the clarification on $...Reason I thought this was this page.
The salient part of that first answer is:
1707859137074.png

The end of that answer actually confuses the issue regarding the sentence you're referencing, because it is only any kind of shortcut for jQuery if the rest of the syntax also matches (which RPG Maker's doesn't).

It's even clarified in the first response:
1707859291183.png


Good luck with your project!

Original thread: https://forums.rpgmakerweb.com/threads/can-i-use-a-formula-inside-of-a-plugins-parameters-instead-of-just-a-number-trying-to-access-screen-width-and-screen-height.165697/