JavaScript questions that don't deserve their own thread

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
11,989
First Language
Indonesian
Primarily Uses
N/A
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
4
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
Regular
Joined
Apr 12, 2012
Messages
6,838
Reaction score
7,852
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
4
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
Regular
Joined
Apr 12, 2012
Messages
6,838
Reaction score
7,852
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
4
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
Regular
Joined
Apr 12, 2012
Messages
6,838
Reaction score
7,852
First Language
English
Primarily Uses
RMMZ
What face did you try changing to?
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
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
Regular
Joined
Apr 12, 2012
Messages
6,838
Reaction score
7,852
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
Regular
Joined
Apr 6, 2016
Messages
278
Reaction score
164
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!
 

Alright

Mr.
Regular
Joined
Sep 24, 2018
Messages
41
Reaction score
443
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
Regular
Joined
Jul 2, 2014
Messages
12,589
Reaction score
11,062
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.
 

Alright

Mr.
Regular
Joined
Sep 24, 2018
Messages
41
Reaction score
443
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
Regular
Joined
Jul 2, 2014
Messages
12,589
Reaction score
11,062
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

Regular
Regular
Joined
Oct 16, 2021
Messages
34
Reaction score
10
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?
 

Alright

Mr.
Regular
Joined
Sep 24, 2018
Messages
41
Reaction score
443
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

Regular
Regular
Joined
Apr 14, 2019
Messages
323
Reaction score
311
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
    {
            
    }
}
 

Alright

Mr.
Regular
Joined
Sep 24, 2018
Messages
41
Reaction score
443
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

Is an extension for the jam time limit from 20 min to 30 min possible? :ysad::ysad::ysad: My entry will have a few battles, it seems >.<
Background and composition study
GAbBmfDaIAAEzVM
Ho, ho, ho and mwah, ha, ha. It appears that I will be getting a leg up on the inclusion of Krampus in the 2023 Game Jam. We arrived in Orlando, FL yesterday and my wife found a Krampus Festival for us to attend tonight! Maybe I will be going home with a Krampus!
I was planning on getting new character management feature into Character Generator, but my recent illness has delayed this somewhat. I will try and get it done today (which would be a miracle) but if not, I will have to complete the whole lot by Tuesday. This should hopefully be fine and all other feature updates should not have their target dates affected.

Forum statistics

Threads
136,707
Messages
1,268,967
Members
180,429
Latest member
starlord6969
Top