JavaScript questions that don't deserve their own thread

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,816
Reaction score
9,155
First Language
Indonesian
Primarily Uses
RMVXA
You can quickly try in the browser by pressing F12 and writing in the console
JavaScript:
var a = 0.9
a *= 0.9
a *= 0.9
to find out.
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
3
First Language
English
Primarily Uses
RMMV
(MV)
Hey y'all.

I'm using DreamX's extension to the Yanfly battle status window and I have everything *mostly* tuned how I want, but I'm having a little trouble with a specific edit.

Currently I have my TP bar set up like this:
f4fa54e67f41e803af49bc1be606aff0.png

Essentially all I want to do is manipulate the font for the TP value, by changing the face.

In the plugin, the method used to draw the TP value is as follows:

JavaScript:
if (!eval(paramTpHideValues)) {
    this.contents.fontSize = eval(paramCurrentValueFontSize);
           
    this.changeTextColor(this.tpColor(actor));
    this.drawText(actor.tp+"%", eval(paramTpValuesX), eval(paramTpValuesY), eval(paramTpValuesWidth), paramTpValuesAlignment);

    this.contents.fontSize = Yanfly.Param.BSWParamFontSize;
}

All I want to do is change the font face before drawText() executes, and then revert it back after drawText() executes (if necessary), but I'm having a little trouble getting that to work. This is built on the Yanfly Core and Yanfly Battle Core plugins, so if there's a function or property within Yanfly MV that can perform this, that'd also work fine.

Any help is appreciated.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
4,986
Reaction score
4,595
First Language
English
Primarily Uses
RMMZ
(MV)
Hey y'all.

I'm using DreamX's extension to the Yanfly battle status window and I have everything *mostly* tuned how I want, but I'm having a little trouble with a specific edit.

Currently I have my TP bar set up like this:
f4fa54e67f41e803af49bc1be606aff0.png

Essentially all I want to do is manipulate the font for the TP value, by changing the face.

In the plugin, the method used to draw the TP value is as follows:

JavaScript:
if (!eval(paramTpHideValues)) {
    this.contents.fontSize = eval(paramCurrentValueFontSize);
          
    this.changeTextColor(this.tpColor(actor));
    this.drawText(actor.tp+"%", eval(paramTpValuesX), eval(paramTpValuesY), eval(paramTpValuesWidth), paramTpValuesAlignment);

    this.contents.fontSize = Yanfly.Param.BSWParamFontSize;
}

All I want to do is change the font face before drawText() executes, and then revert it back after drawText() executes (if necessary), but I'm having a little trouble getting that to work. This is built on the Yanfly Core and Yanfly Battle Core plugins, so if there's a function or property within Yanfly MV that can perform this, that'd also work fine.

Any help is appreciated.
Is there any reason you can't use this.contents.fontFace?
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
3
First Language
English
Primarily Uses
RMMV
Is there any reason you can't use this.contents.fontFace?
1640014626745.png
Good question. That's what I tried initially but it always resulted in this, and I have no idea why.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
4,986
Reaction score
4,595
First Language
English
Primarily Uses
RMMZ
View attachment 210359
Good question. That's what I tried initially but it always resulted in this, and I have no idea why.
The face you're using might size itself differently than the one that was being used before, so you may have to make the size bigger with the new one.
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
3
First Language
English
Primarily Uses
RMMV
The face you're using might size itself differently than the one that was being used before, so you may have to make the size bigger with the new one.
They're from the same font family so I'd be surprised, but more relevantly, even if I change the font size (this.content.fontSize) right after changing the font, nothing changes.

Scratch that, this.content.fontSize actually appears to be changing the y position of the text??
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
4,986
Reaction score
4,595
First Language
English
Primarily Uses
RMMZ
What face did you try changing to?
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
3
First Language
English
Primarily Uses
RMMV
What face did you try changing to?
I'm using Noto Sans Mono Regular as my basic font for values, and I'm trying to change to Noto Sans Mono Black. But the same thing happens even if I try to change to a font such as Arial.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
4,986
Reaction score
4,595
First Language
English
Primarily Uses
RMMZ

hohg

Villager
Member
Joined
Nov 10, 2021
Messages
9
Reaction score
3
First Language
English
Primarily Uses
RMMV
Good evening, everyone. Quick MV question. How do I split notetags into an array? For example something like <note:3,4>. I've seen it done before but sadly I've plum forgotten how to do it.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
278
Reaction score
161
First Language
Swedish
Primarily Uses
N/A
Well, if it is on item 101, then it would be: $dataItems[101].meta.note.split(","). Alternatively $dataItems[101].meta["note"].split(","). If the note name has a space in it, you'll need to use the later version.

I am very sure that "meta" is part of RTP... If it's not get back to me
 

hohg

Villager
Member
Joined
Nov 10, 2021
Messages
9
Reaction score
3
First Language
English
Primarily Uses
RMMV
Well, if it is on item 101, then it would be: $dataItems[101].meta.note.split(","). Alternatively $dataItems[101].meta["note"].split(","). If the note name has a space in it, you'll need to use the later version.

I am very sure that "meta" is part of RTP... If it's not get back to me
Thank you so much, yeah this worked perfectly!
 

McPaul

Villager
Member
Joined
Sep 24, 2018
Messages
18
Reaction score
10
First Language
English
Primarily Uses
RMMV
Greetings.
This should be a really easy answer for the code minded.
I have these lines of code

if (this.isActor()) {
if (this.isStateAffected(500)) {
battler = $dataActors[500];
} else {

Now all I need is to replace the number 500 with a range of 500-1000, which would take one passive state from that range of IDs, then replaces the actors notes with those note of the ID of another actor who has the same ID number as the picked state.
I hope to figure out some kind of variable coding magic trick or something to put in the place of the number 500 instead of having to type the code separately for 500 IDs each.
Can anybody help me?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,600
Reaction score
2,938
First Language
English
Primarily Uses
RMMV
Now all I need is to replace the number 500 with a range of 500-1000
Holy god, you have a thousand states? Anyhow...
if (this.states().some(element => element.id>499 && element.id<1001))
should work for your condition.
 

McPaul

Villager
Member
Joined
Sep 24, 2018
Messages
18
Reaction score
10
First Language
English
Primarily Uses
RMMV
Holy god, you have a thousand states? Anyhow...
if (this.states().some(element => element.id>499 && element.id<1001))
should work for your condition.
Unfortunately this doesn't seem to work. Although I have very little coding knowledge so maybe I just don't know how to copy your line in properly.
Just so if anybody would have any other suggestions, I'll try to explain my issue better.

if (this.isActor()) {
if (this.isStateAffected(500)) { <<<I need this to check if the state ID that the actor has is between 500-1000
battler = $dataActors[500]; <<<<<I need this to return the exact ID number of the state itself
} else {

The code works fine for me, but I'd have to write these four line for each of the 500-1000 states, which isn't hard, but I think it'd be better for the code to keep the whole range in one set of lines lol
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,600
Reaction score
2,938
First Language
English
Primarily Uses
RMMV
Unfortunately this doesn't seem to work. Although I have very little coding knowledge so maybe I just don't know how to copy your line in properly.
I missed the part where you wanted to get the actor of the matching ID.

The problem with what you're asking for is that (unless you have some very strict system with these) there is a possibility that the actor will have more than one state in that range. How should this get resolved in those cases?

Aside from that, this will do what you're asking for.
Code:
if (this.isActor())
{
    var index=-1;
    if ((index=this.states().find(element => element.id>499 && element.id<1001))>-1)
        battler=$dataActors[index];
    else
 

DarielZer0

Villager
Member
Joined
Oct 16, 2021
Messages
27
Reaction score
8
First Language
Spanish
Primarily Uses
RMMV
(MV)
is there a script call that interprete the exact posicion in pixels and not in grids the player or a event is?Cause,well,if i am in the grid 0x,0y i must also be in the pixel 24x,24y(?) and if i move to the grid 3x,0y i should be in pixel 168x,24y(?) if i know this mentally,then probably a script call also,no?
 

McPaul

Villager
Member
Joined
Sep 24, 2018
Messages
18
Reaction score
10
First Language
English
Primarily Uses
RMMV
I missed the part where you wanted to get the actor of the matching ID.

The problem with what you're asking for is that (unless you have some very strict system with these) there is a possibility that the actor will have more than one state in that range. How should this get resolved in those cases?

Aside from that, this will do what you're asking for.
Code:
if (this.isActor())
{
    var index=-1;
    if ((index=this.states().find(element => element.id>499 && element.id<1001))>-1)
        battler=$dataActors[index];
    else
Unfortunately this didn't work either, but I think I made some progress.
I rewrote the code this way and it works like it used to while I give the index variable any of my rigged state ids.

if (this.isActor()) {
var index=500;
if (this.isStateAffected(index)) {
battler = $dataActors[index];
} else {

I spent a couple of hours trying to put the index variable into a range of 500-1000 with all kinds of brackets, but nothing works.
 

BurningOrca

Veteran
Veteran
Joined
Apr 14, 2019
Messages
282
Reaction score
259
First Language
German
Primarily Uses
RMMZ
Unfortunately this didn't work either, but I think I made some progress.
I rewrote the code this way and it works like it used to while I give the index variable any of my rigged state ids.

if (this.isActor()) {
var index=500;
if (this.isStateAffected(index)) {
battler = $dataActors[index];
} else {

I spent a couple of hours trying to put the index variable into a range of 500-1000 with all kinds of brackets, but nothing works.
The code from ATT_Turan did not work, because the find function does not return the index of the object in the array, but the object itself. It does return undefined, if the object cannot be found. The following amended version should work a little better:
JavaScript:
if( this.isActor() )
{
    const firstAffectedStateInRange = this.states().find(element => element.id > 499 && element.id < 1001);
    if( firstAffectedStateInRange !== undefined )
    {
        battler = $dataActors[firstAffectedStateInRange.id];
    }
    else
    {
            
    }
}
 

McPaul

Villager
Member
Joined
Sep 24, 2018
Messages
18
Reaction score
10
First Language
English
Primarily Uses
RMMV
The code from ATT_Turan did not work, because the find function does not return the index of the object in the array, but the object itself. It does return undefined, if the object cannot be found. The following amended version should work a little better:
JavaScript:
if( this.isActor() )
{
    const firstAffectedStateInRange = this.states().find(element => element.id > 499 && element.id < 1001);
    if( firstAffectedStateInRange !== undefined )
    {
        battler = $dataActors[firstAffectedStateInRange.id];
    }
    else
    {
          
    }
}
Took me a minute to rearrange the brackets, all the while the game kept crashing at battle, but in the end it began to work, all tests passed. And there I though this would be a really simple fix.
Thank you. I won't forget it.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Never thought a day would come during summer when Id have to wear a sweater and two pairs of socks...
And today we got some insides maps from the town i posted last time.

Map044.png
Map045.png
Map046.png
Map047.png Map048.png Map049.png Map050.png
So a big bug that was on a glue trap at home is now magically not on the glue trap. This feeling of terror I'm experiencing could be a fun thing to put in my game project (not the IGMC one).
Hoping that Unite has a character generator with black hairs/lips and other features.. it is such a pain making characters without these...

Forum statistics

Threads
123,410
Messages
1,156,345
Members
161,858
Latest member
Renbo
Top