JavaScript questions that don't deserve their own thread

Aryn

Veteran
Veteran
Joined
Jun 24, 2017
Messages
33
Reaction score
10
First Language
English
Primarily Uses
RMMV
I'm piggy-backing on this question, because the original code is close to what I'm wrestling with. I think this should be fairly simple, but I can't get Galv's Spawn Timers to take a variable instead of a straight number. I don't see any reason that should be the case. Is there?

E.g.,
Code:
this.setSpawn(8,3,$gameVariables.value(1));
V[1] shows as set to 60 after the code runs, but the timer doesn't start. Thank you in advance!
EDIT: for syntax to distinguish string/not string
If anyone is interested, I solved this today by adding a few lines to the Game_Interpreter part of the plugin code. I'm pretty new to javascript, so there's probably a more efficient way, but this works. This addition allows you to pass a "v#" string in the argument and it will change "time" to the value of the variable (e.g., this.setSpawn(0,0,"v2") will make a timer on this event for however many seconds as the value of $game.Variables.value(2)):

Code:
Game_Interpreter.prototype.setSpawn = function(mapId,eventId,time) {
    if (mapId <= 0) mapId = this._mapId;
    if (eventId <= 0) eventId = this._eventId;
    $gameSystem.eventTimers[mapId] = $gameSystem.eventTimers[mapId] || {};
        //time by string variable if includes "v"
    var x = typeof time
    if (x == "string") {
        var arr1 = time.split("")   
        if (arr1[0] == "v") {
            time = Number(time.replace("v",""))
            time = $gameVariables.value(time)
        }
    }
    $gameSystem.eventTimers[mapId][eventId] = $gameSystem.playtime() + time;
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
807
First Language
English
Primarily Uses
RMMV
Is there a more elegant way to implement a state that reduces DEF by the caster's ATK. This is wut I got so far, but there are possible flaws w/ this (such as if the caster's ATK changes between when the state was inflicted and when it's removed.
Code:
<Custom Apply Effect>
  target._paramPlus[3] -= origin.atk;
</Custom Apply Effect>
<Custom Remove Effect>
  target._paramPlus[3] += origin.atk;
</Custom Remove Effect>
Ideally, I'd prefer the DEF debuff to be attached to the state and not directly alter the target's stats like in my example. (That way the effects are automatically undone when the state is removed)
 

Sardonic

Veteran
Veteran
Joined
Sep 3, 2016
Messages
34
Reaction score
21
First Language
English
Primarily Uses
I'm working on customizing the message window in my project and I need to offset the text vertically.

Where does the code set the y position of the text in the message window? I looked for drawtext in the code but couldn't seem to find it as it relates to the message window.

My problem is a bit complex because I have increased the vertical size of the message window in order to accommodate a larger face picture, but as a result the text itself is moved upwards. Decreasing the size of the window brings the text down to where I want it, but then part of the face picture is cut off.

I basically would like to know of any way to reposition the text in the message window vertically. I need a method that does not move the face picture. Thus, moving the entire window is out of the question.

I am using yanfly message core along with its extensions.
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
222
Reaction score
191
First Language
English
Primarily Uses
RMMV
@Sardonic It's in the newPage function of Window_Message in rpg_windows.js. So you could just alias the function and set textState.y to whatever you want (in the code below, I've set the text to start one line down). You could also set it to a number or this.lineHeight() * 2, for example.

I only tried this with Yanfly's Message Core and the first extension. I didn't go through Yanfly's plugins to see if they modified the newPage function or not, but you can copy the code below and put it in a new plugin below Yanfly's plugins.

Code:
var Window_Message_newPage_changeY = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function(textState) {
    Window_Message_newPage_changeY.call(this, textState);
    textState.y = this.lineHeight();
};
 

Sardonic

Veteran
Veteran
Joined
Sep 3, 2016
Messages
34
Reaction score
21
First Language
English
Primarily Uses
Code:
var Window_Message_newPage_changeY = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function(textState) {
    Window_Message_newPage_changeY.call(this, textState);
    textState.y = this.lineHeight();
};
This worked perfectly, thanks!
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
807
First Language
English
Primarily Uses
RMMV
Have nary a response in my thread so gonna try my luck here...
I'm trying to use YEP_MainMenuManager to make a shortcut that goes directly to the skill equip screen instead of going skills -> skill equip. Skill Equip is from YEP_EquipBattleSkills btw.EBStoMMM.png
I just need help filling out the blanks to create the shortcut.
 

Pootscooter

Veteran
Veteran
Joined
Jun 7, 2020
Messages
41
Reaction score
10
First Language
Mandarin
Primarily Uses
RMMV
Quick question: When I create a var within a notetag, can that var be used outside that notetag?
Example:
<Custom Initiate Effect>
var stuff = 420;
$gameMessage.add('happy ' + stuff);
</Custom Initiate Effect>
<Custom Conclude Effect>
stuff += 1;
</Custom Conclude Effect>

This is just a random example I made up, it has nothing to do w/ wut I'm making. I just want to know if the var will persist outside the notetage it was created in, which in this case is <Custom Initiate Effect>
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
807
First Language
English
Primarily Uses
RMMV
How do I reference attackTimes+ in a damage formula? I've tried "user.attackTimesAdd()" but it doesn't work... I'm just looking for the correct syntax to reference this trait. Thx.
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
449
Reaction score
1,402
First Language
Indonesia
Primarily Uses
RMMV
Uuuh, JS quick question...
Is there a way to measure text width without creating a new bitmap?
I know Bitmap.measureTextWidth, but I just need the text width in pixel to update in real time.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Uuuh, JS quick question...
Is there a way to measure text width without creating a new bitmap?
I know Bitmap.measureTextWidth, but I just need the text width in pixel to update in real time.
If Bitmap.measureTextWidth is not the width in pixels, what is the measuring unit? I'd also like to know how to measure text width in pixels.
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
449
Reaction score
1,402
First Language
Indonesia
Primarily Uses
RMMV
If Bitmap.measureTextWidth is not the width in pixels, what is the measuring unit? I'd also like to know how to measure text width in pixels.
Uhh, Bitmap.measureTextWidth return text width in pixel. I just thought creating new bitmap just to use that particular function in real time is expensive.
Or is that already the cheapest way?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,358
Reaction score
1,520
First Language
English
Primarily Uses
RMMV
Why are you creating a new bitmap just to use it? Presumably if you have something that's displaying text, there's already a Bitmap object there that can call it.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Uhh, Bitmap.measureTextWidth return text width in pixel. I just thought creating new bitmap just to use that particular function in real time is expensive.
Or is that already the cheapest way?
ok so I think maybe this could help you:
There is a Window_Base.prototype.textWidth(text) function, that you can just use anytime during the game. You just have to use any type of window in the game. So for example use a window that is always on the map, if you want to check a text width on a map, like Window_MapNameWindow:

SceneManager._scene._mapNameWindow.textWidth("hello")

As long as the window exists in the scene where you want to check the text width you can use that.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
While I'm here, I have a question not worth it's own thread:

How can I add Text to a scene without using windows. Like a simple HUD Text such as "Player Name" on the Map Scene. Is there a way to create a Text Sprite, which has the same properties as a Image Sprite?

For example, something like this:
weaponImage = new Sprite(ImageManager.loadMenuWeapon("weapons_ar_goliath_inspect"));
SceneManager._scene.addChild(weaponImage);

But with a costum, free floating, non-Window, Text.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,418
Reaction score
669
First Language
Portuguese - Br
Primarily Uses
RMMV
@Lanzy
You can do something like that:
JavaScript:
const newSprite = new Sprite();
newSprite.bitmap = new Bitmap(width,height);
const text = "Your text here".
newSprite.bitmap.drawText(text, X, Y, width, lineHeight, 'center')
SceneManager._scene.addChild(newSprite);
Example:

JavaScript:
const text = "Hello World".
const newSprite = new Sprite();
newSprite.bitmap = new Bitmap(200,200);
newSprite.bitmap.drawText(text, 0, 0, 200, 32, 'center')
SceneManager._scene.addChild(newSprite);
You can define the properties fo the Bitmap too, like fontSize, italic etc...
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,358
Reaction score
1,520
First Language
English
Primarily Uses
RMMV
While I'm here, I have a question not worth it's own thread:

How can I add Text to a scene without using windows. Like a simple HUD Text such as "Player Name" on the Map Scene. Is there a way to create a Text Sprite, which has the same properties as a Image Sprite?

For example, something like this:
weaponImage = new Sprite(ImageManager.loadMenuWeapon("weapons_ar_goliath_inspect"));
SceneManager._scene.addChild(weaponImage);

But with a costum, free floating, non-Window, Text.
Not easily. drawText is theoretically callable on any instance of the Bitmap class, but you still need a Bitmap there to draw on. Using transparent windows is the most convenient method if you just want some text on the map screen.

@Eliaquim's method is a good suggestion too.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
@Lanzy
You can do something like that:
JavaScript:
const newSprite = new Sprite();
newSprite.bitmap = new Bitmap(width,height);
const text = "Your text here".
newSprite.bitmap.drawText(text, X, Y, width, lineHeight, 'center')
SceneManager._scene.addChild(newSprite);
Example:

JavaScript:
const text = "Hello World".
const newSprite = new Sprite();
newSprite.bitmap = new Bitmap(200,200);
newSprite.bitmap.drawText(text, 0, 0, 200, 32, 'center')
SceneManager._scene.addChild(newSprite);
You can define the properties fo the Bitmap too, like fontSize, italic etc...

I wasn't aware that you need to first create an empty Sprite and then add a Bitmap to it. Thank you for your speedy response!

Sorry, one more question regarding loading sprites on map:
Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,358
Reaction score
1,520
First Language
English
Primarily Uses
RMMV
Sorry, one more question regarding loading sprites on map:
Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
The blt (block transfer) function which displays a loaded bitmap on another one takes dw and dh as additional parameters, which allow you to draw it at a bigger/smaller size than the source.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
The blt (block transfer) function which displays a loaded bitmap on another one takes dw and dh as additional parameters, which allow you to draw it at a bigger/smaller size than the source.
Muchas gracias!
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,418
Reaction score
669
First Language
Portuguese - Br
Primarily Uses
RMMV
I wasn't aware that you need to first create an empty Sprite and then add a Bitmap to it. Thank you for your speedy response!

Sorry, one more question regarding loading sprites on map:
Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
You can also use the scale.x and scale.y(or scaleX / scaleY?) Can't remember now, but you can use it to change the scale:
newSprite.scale.x = 2
newSprite.scale.y = 2
The default is 1.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

What is your favourite rpg maker plugin?
Hopefully this gets fixed before release..
Where's this sudden heatwave come from? It's not even sunny, it's just hot. Hate it!
I'm slightly disappointed that the MZ codebase still uses core.js, managers.js, objects.js, scenes.js, sprites.js and windows.js instead of core/Bitmap.js, core/Graphics.js, managers/AudioManager.js, managers/DataManager.js, etc...
just a few more hours until the toughest, most pressure 72 hours of my life, wish me luck guys

Forum statistics

Threads
100,565
Messages
977,269
Members
132,148
Latest member
jcamp10565
Top