JavaScript questions that don't deserve their own thread

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
151
Reaction score
133
First Language
English
Primarily Uses
RMMZ
Is there a way to check the user base param in MZ?

user.agi gives me the total agi. I just want the base wo equip or buff value.

Thanks
JavaScript:
Game_Actor.prototype.paramBase = function(paramId) {
    return this.currentClass().params[paramId][this._level];
};

This is how the base script does it. So if you just want to find the current base, I think it would be user.paramBase(paramId). Use the id for the param you want to find, obviously. agi is 6, I believe.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
216
Reaction score
124
First Language
French
Primarily Uses
RMMV
Is there a way to refresh the battle status window? I'm trying to change its height based on the number of current party members, but it doesn't refresh mid-battle when I change the value returned by Window_BattleStatus.prototype.numVisibleRows.
 

MikeMakes

Veteran
Veteran
Joined
Sep 30, 2015
Messages
193
Reaction score
47
First Language
English
Primarily Uses
For sprites created like below, how do I update the image later after?

this._face = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId));
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
216
Reaction score
124
First Language
French
Primarily Uses
RMMV
For sprites created like below, how do I update the image later after?

this._face = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId));
Try using this command instead: $gameActors.actor(actorId).setFaceImage("faceName", faceIndex)
This will do the command you mentioned but apply the change correctly, it's the equivalent of the event command. What you entered doesn't set the index.
Replace actorId by the actor's database ID, faceName with the file name of the faceset, and faceIndex by the index of the face you want to use, starting from 0 and in reading order.
Example: $gameActors.actor(1).setFaceImage("Actor1", 0)
 

MikeMakes

Veteran
Veteran
Joined
Sep 30, 2015
Messages
193
Reaction score
47
First Language
English
Primarily Uses
While I'm looking for something different, that's actually helpful to know as well, CHKNRAVE. :cutesmile:

I'm looking for a solution for updating sprites that are drawn in menus in general, maybe through:

this.drawPicturename('PicName', 0, 0);

Window_Name.prototype.drawPicturename = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y);
};

Is something like Update and Refresh needed? How does that look like?
 
Last edited:

FirestormNeos

Veteran
Veteran
Joined
Jul 23, 2019
Messages
191
Reaction score
148
First Language
English
Primarily Uses
RMMV
Where's the part of the MV engine that hard-codes the base stat of Luck to have a minimum of (positive) 1, and can I change the stat's minimum to negative 99 (or negative 999) without causing issues?
 
Last edited:

ChinaLake

Villager
Member
Joined
Feb 20, 2021
Messages
16
Reaction score
3
First Language
English
Primarily Uses
RMMV
Is it better to buy the full version Alpha ABS plugin by Pheonix KageDesu or to subscribe to his ******* and get it there?
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
141
Reaction score
58
First Language
English
Primarily Uses
RMMV
While I'm looking for something different, that's actually helpful to know as well, CHKNRAVE. :cutesmile:

I'm looking for a solution for updating sprites that are drawn in menus in general, maybe through:

this.drawPicturename('PicName', 0, 0);

Window_Name.prototype.drawPicturename = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y);
};

Is something like Update and Refresh needed? How does that look like?

Sprites are usually updated via the MyWindow.updateCursor() function.
Let me know if that helped

Where's the part of the MV engine that hard-codes the base stat of Luck to have a minimum of (positive) 1, and can I change the stat's minimum to negative 99 (or negative 999) without causing issues?

Check out the data folder of your project and open Classes.json file. You can manually change every parameter of every class to whatever you desire. The params array stores every stat of every param for every level. So it's gonna be a loong list. The luck stat is in param[7], so the 8th array within the param array.

For better understanding, this is the function that accesses the param base of every stat:

JavaScript:
//note that for luck stat the paramId is 7
Game_Actor.prototype.paramBase = function (paramId) {
    return this.currentClass().params[paramId][this._level];
};
 
Last edited:

MikeMakes

Veteran
Veteran
Joined
Sep 30, 2015
Messages
193
Reaction score
47
First Language
English
Primarily Uses
I probably misused the "update" term.

How do I reflect changes to a window's sprite if, for example, a variable changes from 1 to 2 which determines which .png graphic to display:

if ($gameVariables.value(1) == 1) {
this.drawPicturename('PicNameA', 0, 0);
}

if ($gameVariables.value(1) >= 2) {
this.drawPicturename('PicNameB', 0, 0);
}

Window_Name.prototype.drawPicturename = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y);
};

==============

I hope to update sprites depending on certain changes in battle even to like (this is an example):
if 2 enemies, draw picture of sun
if 1 enemy left after defeating other one, update the sun to picture of moon
Seems like when I draw the initial picture based on condition, it doesn't change once it meets another criteria.


Thanks
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
141
Reaction score
58
First Language
English
Primarily Uses
RMMV
I probably misused the "update" term.

How do I reflect changes to a window's sprite if, for example, a variable changes from 1 to 2 which determines which .png graphic to display:

if ($gameVariables.value(1) == 1) {
this.drawPicturename('PicNameA', 0, 0);
}

if ($gameVariables.value(1) >= 2) {
this.drawPicturename('PicNameB', 0, 0);
}

Window_Name.prototype.drawPicturename = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y);
};

==============

I hope to update sprites depending on certain changes in battle even to like (this is an example):
if 2 enemies, draw picture of sun
if 1 enemy left after defeating other one, update the sun to picture of moon
Seems like when I draw the initial picture based on condition, it doesn't change once it meets another criteria.


Thanks
With the contents canvas on windows the sprites "bleed" onto the canvas so to speak. So 10 sprites in a window become one big canvas that is static. Meaning, you have to clear the contents before drawing a new picture.

So try this first:
JavaScript:
if ($gameVariables.value(1) == 1) {
this.contents.clear();
this.drawPicturename('PicNameA', 0, 0);
}

However, there is another way to mess with sprites and have more control over them.

JavaScript:
Window_Name.prototype.drawPicturename = function(filename, x, y)    {
    //create a sprite to house the bitmap
    let spr = new Sprite();   
    let bitmap = ImageManager.loadPicture(filename);
    spr.bitmap = bitmap;
    //I'm sure there is a spr.position.set function or something like that
    //for easiert coding
    //note that x and y are anchored at the window's corner, not the screen's
    spr.x = x;
    spr.y = y;
    //add the sprite to a new window property named after the file
    this["_" + filename] = spr;
    //add it as a child otherwise you won't see it
    this.addChild(spr);
};

This way you have more control over the sprites. You can actively move them around, set opacity etc.

You can then access the sprite like this:
Window_Name._filename

I suggest you create both images in the beginning and set only one to visible and then switch visibility as necessary to show either moon or sun. Let me know if this helped.
 

rexie09

Villager
Member
Joined
Apr 4, 2021
Messages
23
Reaction score
9
First Language
English
Primarily Uses
RMMZ
I have been trying for a while with no avail and was wondering if there was a way to change a actors Max hp either by using the mhp variable or another way
 

Lady_JJ

Veteran
Veteran
Joined
May 6, 2019
Messages
229
Reaction score
132
First Language
English
Primarily Uses
RMMZ
@rexie09 I don't think you need a script. There's an event tab 1: Actor > Change Parameter > MaxHP.
 

rexie09

Villager
Member
Joined
Apr 4, 2021
Messages
23
Reaction score
9
First Language
English
Primarily Uses
RMMZ
@rexie09 I don't think you need a script. There's an event tab 1: Actor > Change Parameter > MaxHP.
Thank you for the answer i was not aware of that but i needed a way to add max hp in a script. You telling me about allowed me to find the function addParam that will do what i was looking for.
 

MikeMakes

Veteran
Veteran
Joined
Sep 30, 2015
Messages
193
Reaction score
47
First Language
English
Primarily Uses
With the contents canvas on windows the sprites "bleed" onto the canvas so to speak. So 10 sprites in a window become one big canvas that is static. Meaning, you have to clear the contents before drawing a new picture.

So try this first:
JavaScript:
if ($gameVariables.value(1) == 1) {
this.contents.clear();
this.drawPicturename('PicNameA', 0, 0);
}

However, there is another way to mess with sprites and have more control over them.

JavaScript:
Window_Name.prototype.drawPicturename = function(filename, x, y)    {
    //create a sprite to house the bitmap
    let spr = new Sprite();  
    let bitmap = ImageManager.loadPicture(filename);
    spr.bitmap = bitmap;
    //I'm sure there is a spr.position.set function or something like that
    //for easiert coding
    //note that x and y are anchored at the window's corner, not the screen's
    spr.x = x;
    spr.y = y;
    //add the sprite to a new window property named after the file
    this["_" + filename] = spr;
    //add it as a child otherwise you won't see it
    this.addChild(spr);
};

This way you have more control over the sprites. You can actively move them around, set opacity etc.

You can then access the sprite like this:
Window_Name._filename

I suggest you create both images in the beginning and set only one to visible and then switch visibility as necessary to show either moon or sun. Let me know if this helped.

Really appreciated the explanation, Lanzy.

The first method is fine for now. I'll definitely try the other one once I become more comfortable with JS.
 

BurningOrca

Veteran
Veteran
Joined
Apr 14, 2019
Messages
229
Reaction score
201
First Language
German
Primarily Uses
RMMV
In MV in DataManager.saveGameWithoutRescue there is warning if the length of the save data string is equal to or exceeds 200.000 Characters. Suppose you have so many plugins installed, which all add something to the save data, so that it will actually happen, would this be problematic or can you ignore the warning if you know it is okay? Does the warning just exist to inform the game creators that there may be something wrong with their project or is there really a limit to the save file size? I've tested it on the console by adding a string of 400.000 Random Characters to $gamePlayer and it was saved and loaded correctly. So I started to wonder.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
567
Reaction score
244
First Language
PT-BR
Primarily Uses
RM2k3
@BurningOrca
Sorry if I'm wrong, but I have already accessed sites that froze my browser for some Javascript code that loads a lot of data in a very short time.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
216
Reaction score
124
First Language
French
Primarily Uses
RMMV
Hi everybody,

I was looking through Aesica's plugins on Github to learn from people who are better than me, and I found that they do this after the plugin parameters:
JavaScript:
(function($$)
{
    $$.itemType = {"item":0,"weapon":1,"armor":2,"gold":3};

In the template I got from this forum, I saw the function line having no arguments.
On my side, I tried this bit of code:
JavaScript:
(function($$) {
    $$.stuff = "thing";
    console.log($$);
})();
But the console returns an error at the part where I try to define $$.stuff, saying $$ is undefined.

Can somebody tell me what this $$ is about?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,418
Reaction score
2,516
First Language
English
Primarily Uses
RMMZ
Hi everybody,

I was looking through Aesica's plugins on Github to learn from people who are better than me, and I found that they do this after the plugin parameters:
JavaScript:
(function($$)
{
    $$.itemType = {"item":0,"weapon":1,"armor":2,"gold":3};

In the template I got from this forum, I saw the function line having no arguments.
On my side, I tried this bit of code:
JavaScript:
(function($$) {
    $$.stuff = "thing";
    console.log($$);
})();
But the console returns an error at the part where I try to define $$.stuff, saying $$ is undefined.

Can somebody tell me what this $$ is about?
If you look at the very end of the plugin, it contains the name of the variable that $$ relates to in parentheses afterwards; in the case of autosave, for example, it has (Aesica.Autosave), which was defined earlier in the plugin. The $$ itself doesn't mean anything at all, it's literally just the name of the function variable Aesica chose to represent what gets passed to the function when it's called.

Yours doesn't work because your anonymous function call just has parentheses with no parameter passed, so $$ has nothing to relate to.
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,044
Reaction score
853
First Language
French
I've seen this one but don't remember the syntax (as usual <__<), what's the script line to add a buff to a character?
 
Last edited:

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
141
Reaction score
58
First Language
English
Primarily Uses
RMMV
I've seen this one but don't remember the syntax (as usual <__<), what's the script line to add a buff to a character?

Another question that probably has an easy answer...
This is to set a value to a variable:
Code:
$gameVariables.setValue(ID, value);

How do I add a number instead of just setting it? Like +100%
target.addBuff(effect.dataId, effect.value1)
 

Latest Threads

Latest Posts

Latest Profile Posts

Phew! logged back. Seems I was too occupied with 3D learning (yeah for RPGM purposes) creating IRL space, trying to grow catnip, dealing with health and DC is good. (so MrC) ^^
Currently trying to add items in the same style as Kyrise's excellent icons. I like having a large variety of items :3 KyriseandMe.PNG
Create MiniMaps, Sprites for MV Enemies, & Aethereal Plane Battlebacks | RPG Maker News #74

Vtubers Vs MOTHER.png

This might be my next project. You like it?
I'm off to search the master script list for my skill issue. HOORAY! FUN!

Forum statistics

Threads
112,328
Messages
1,067,420
Members
145,967
Latest member
zakariadu78
Top