JavaScript questions that don't deserve their own thread

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
141
Reaction score
42
First Language
English
Primarily Uses
RMMV
Hi All, I am trying to make it such that any of my characters with 2-handed training will cause their weapons to have higher atk. Using YEP's Equip Core for RMMV, I tried the following, but it does not seem to work. Really appreciate it if anyone could take a look and see where I went wrong, please?

<Custom Parameters>
if (user.isStateAffected(407) && user.equips()[1] == null) {
atk *= 2;
} else if (user.isStateAffected(407) && user.equips()[1].aTypeId == 1) {
atk *= 2;
} else {
atk *= 1;
}
</Code Parameters>

In the first line, I am trying to check if the user has 2-handed training under State ID 407, and if their 2nd equipment slot (I understand 0 is first slot, and 1 is second slot, so not sure if this is the problem) is empty. The second check is to see if the user has State ID 407, and if they are equipping a Small Shield (my Armor Types start with Small Shield as the first item in the system).

Thanks in advance!
 

MikeMakes

Veteran
Veteran
Joined
Sep 30, 2015
Messages
200
Reaction score
48
First Language
English
Primarily Uses
What is the script to set player direction based on a variable?
(e.g. assuming direction value was assigned to variable 4 already)
 
Last edited:

Restart

Veteran
Veteran
Joined
Mar 15, 2019
Messages
832
Reaction score
670
First Language
English
Primarily Uses
RMMV
What is the script to set player direction based on a variable?
(e.g. assuming direction value was assigned to variable 4 already)
$gamePlayer.setDirection($gameVariables.value(4))
will work, I believe.
 

Klammsi

Veteran
Veteran
Joined
Nov 19, 2016
Messages
87
Reaction score
10
First Language
English
Primarily Uses
Hey everybody,

Hope you are all well. I am tinkering around with some of the lunatic function form Yanfly's Row Formation Plugin


What I would like to achieve is:
Once all alive members of row 1 are affected by a state ("disabled") remove a different sate ("protected") from all alive members of row 2.
No unfortunately my Java Script knowledge is very limited but by looking at other peoples code and testing, I managed to figure out how to add or remove states from alive row members using this:

var m = $gameTroop.rowAliveMembers(1).length \\(1)That stands for row 1
var member = $gameTroop.rowAliveMembers(1)

for (var i = 0; i<m; i++){
member.addState(13)
}

Would I be able to apply this to an "if" statement to achieve what I am looking for?
I guess I would have to declare variables for row2 as well?

Any help would be greatly appreciated,
Thank you
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
Hi All, I am trying to make it such that any of my characters with 2-handed training will cause their weapons to have higher atk. Using YEP's Equip Core for RMMV, I tried the following, but it does not seem to work. Really appreciate it if anyone could take a look and see where I went wrong, please?

<Custom Parameters>
if (user.isStateAffected(407) && user.equips()[1] == null) {
atk *= 2;
} else if (user.isStateAffected(407) && user.equips()[1].aTypeId == 1) {
atk *= 2;
} else {
atk *= 1;
}
</Code Parameters>

In the first line, I am trying to check if the user has 2-handed training under State ID 407, and if their 2nd equipment slot (I understand 0 is first slot, and 1 is second slot, so not sure if this is the problem) is empty. The second check is to see if the user has State ID 407, and if they are equipping a Small Shield (my Armor Types start with Small Shield as the first item in the system).

Thanks in advance!
You have a typo in your code - to be fair, it's because Yanfly has a typo in part of his documentation. Your notetag starts with <Custom Parameters>, so it needs to end with </Custom Parameters>, not </Code Parameters>.

Also, there's no reason to have else atk *= 1 at the end. Your atk is always equal to itself times 1, so that line doesn't change anything - why bother typing it?

Hey everybody,

Hope you are all well. I am tinkering around with some of the lunatic function form Yanfly's Row Formation Plugin
I'm not sure why you're crossposting here instead of your dedicated thread that has all your information in it. Also, because it references functions that are specific to a plugin, it really should be in that thread or its own new thread, not in a generic JavaScript thread.
However!
What I would like to achieve is:
Once all alive members of row 1 are affected by a state ("disabled") remove a different sate ("protected") from all alive members of row 2.
No unfortunately my Java Script knowledge is very limited but by looking at other peoples code and testing, I managed to figure out how to add or remove states from alive row members using this:
This premise is a bit confusing, because you don't explain where this code is going, which affects how it would be done. Is it being executed by an event that you're calling at a specific time? Are you trying to put it inside a state or something else?
var m = $gameTroop.rowAliveMembers(1).length \\(1)That stands for row 1
var member = $gameTroop.rowAliveMembers(1)

for (var i = 0; i<m; i++){
member.addState(13)
}
This code would add state 13 to all living members in your first row, except you are using incorrect JavaScript syntax - you need to do some tutorials to learn about some basic elements such as variables and arrays. rowAliveMembers() (which is what you set your variable member to) returns an array, which is a list of variables.

Saying member.addState() does nothing, because your list doesn't have an addState function. You can also tell you're doing something wrong because you created a variable i, you're incrementing it, but not using it for anything.

The correct syntax to add state 13 to all of your people is member.addState(13);

Additionally, there's no real point to the variables you're creating. We make variables when we 1) need to create a value or entity that we can manipulate, 2) want to change values without changing them in the place they came from, or 3) are going to type the same thing a bunch of times and want to save effort. Neither is true for you, so it's less typing for you to write:
Code:
for (var i = 0; i<$gameTroop.rowAliveMembers(1).length; i++)
    $gameTroop.rowAliveMembers(1)[i].addState(13);

Now...
Would I be able to apply this to an "if" statement to achieve what I am looking for?
No? Your code has nothing to do with row 2 at all right now. You wrote code that is giving a state to row 1, which has nothing to do with checking a state in row 1 or giving a state to row 2.

To do what you want requires an entirely different piece of code than this.

I'm very confused why you produced this code and posted it here when you had so much correct material in your other thread. You literally were given a function to do what you're trying to do here.
I guess I would have to declare variables for row2 as well?
Definitely not. Again, you seem to have a poor understanding of what variables are for - refer to my list above, and consider doing some tutorials.

You should resume posting in the thread you created, or make a new one if you feel there's some reason to - any further explanation of it here will hijack this thread.
 

Klammsi

Veteran
Veteran
Joined
Nov 19, 2016
Messages
87
Reaction score
10
First Language
English
Primarily Uses
You have a typo in your code - to be fair, it's because Yanfly has a typo in part of his documentation. Your notetag starts with <Custom Parameters>, so it needs to end with </Custom Parameters>, not </Code Parameters>.

Also, there's no reason to have else atk *= 1 at the end. Your atk is always equal to itself times 1, so that line doesn't change anything - why bother typing it?


I'm not sure why you're crossposting here instead of your dedicated thread that has all your information in it. Also, because it references functions that are specific to a plugin, it really should be in that thread or its own new thread, not in a generic JavaScript thread.
However!

This premise is a bit confusing, because you don't explain where this code is going, which affects how it would be done. Is it being executed by an event that you're calling at a specific time? Are you trying to put it inside a state or something else?

This code would add state 13 to all living members in your first row, except you are using incorrect JavaScript syntax - you need to do some tutorials to learn about some basic elements such as variables and arrays. rowAliveMembers() (which is what you set your variable member to) returns an array, which is a list of variables.

Saying member.addState() does nothing, because your list doesn't have an addState function. You can also tell you're doing something wrong because you created a variable i, you're incrementing it, but not using it for anything.

The correct syntax to add state 13 to all of your people is member.addState(13);

Additionally, there's no real point to the variables you're creating. We make variables when we 1) need to create a value or entity that we can manipulate, 2) want to change values without changing them in the place they came from, or 3) are going to type the same thing a bunch of times and want to save effort. Neither is true for you, so it's less typing for you to write:
Code:
for (var i = 0; i<$gameTroop.rowAliveMembers(1).length; i++)
    $gameTroop.rowAliveMembers(1)[i].addState(13);

Now...

No? Your code has nothing to do with row 2 at all right now. You wrote code that is giving a state to row 1, which has nothing to do with checking a state in row 1 or giving a state to row 2.

To do what you want requires an entirely different piece of code than this.

I'm very confused why you produced this code and posted it here when you had so much correct material in your other thread. You literally were given a function to do what you're trying to do here.

Definitely not. Again, you seem to have a poor understanding of what variables are for - refer to my list above, and consider doing some tutorials.

You should resume posting in the thread you created, or make a new one if you feel there's some reason to - any further explanation of it here will hijack this thread.
Hello mate,

I am working my way through the Java Script tutorials that you recommended at the moment.
Just stumbled upon the code above and though this might have been a solution to the problem that I was facing...
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
Hello mate,

I am working my way through the Java Script tutorials that you recommended at the moment.
Just stumbled upon the code above and though this might have been a solution to the problem that I was facing...
It applies a state to everyone in the first row. Logically, just saying out loud what that does and what you want to do, that's pretty unrelated :wink:

I'm happy (as I'm sure are others) to continue giving you pointers if you're still working your way through it, but not to derail this thread.
 

rexie09

Villager
Member
Joined
Apr 4, 2021
Messages
26
Reaction score
10
First Language
English
Primarily Uses
RMMZ
Hello is there any way to set the value of a items meta to a different value instead of just true in the note area and not with a function.
here is a image if you have no idea what i mean by meta.help me please.PNG
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
Look at almost any plugin that uses notetags to provide functionality, very few of them are just <This Thing is True>, most use them as a header for additional data - you can see how to read that information in.

I'm not sure what you mean by "and not with a function" - you'll need to use a parsing function in your code to interpret the text you're putting in the notetag as whatever kind of information you want it to end up being.
 

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
141
Reaction score
42
First Language
English
Primarily Uses
RMMV
@ATT_Turan Thank you for pointing out the typo. No idea why I did not notice it before. In any case, I managed to make it work thanks to you.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
You probably just copied it from the help file, where it has the same typo, and never thought to actually read it :smile:
 

JouleHuece

Villager
Member
Joined
Apr 5, 2021
Messages
11
Reaction score
0
First Language
English
Primarily Uses
RMMV
Is there a way to change the colors of the keyboard in of YEP_KeyboardConfig.js?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
Is there a way to change the colors of the keyboard in of YEP_KeyboardConfig.js?
There are plugin parameters to do it - Assigned Color and Action Color.

If you want to change the rest of the keyboard, it uses your game's standard gauge back color. That's defined in rpg_windows.js as color 19. So you could change that either by making a plugin function to change that returned value (which would change all your gauges), or by changing line 813 in the plugin to return a different color number which would affect just the keyboard screen.

(I'm not sure why you thought this question didn't deserve a thread - you're not even asking a JavaScript question, you're asking about a specific plugin)
 

Boonty

Veteran
Veteran
Joined
Oct 10, 2018
Messages
132
Reaction score
49
First Language
French
Primarily Uses
RMMV
Hey everyone.

I would like to set my Variable 3 to be the sum of the inventory weapons id from 3 to 29.

Could you help me with that ? :)
 

Jragyn

JABS codemonkey
Veteran
Joined
Aug 14, 2012
Messages
221
Reaction score
172
First Language
English
Primarily Uses
RMMZ
Hello is there any way to set the value of a items meta to a different value instead of just true in the note area and not with a function.
here is a image if you have no idea what i mean by meta.View attachment 186330

What is circled in this image is a direct result of putting:
JavaScript:
<randomEnable>
in a note box somewhere (looks like a weapon judging by the rest of the data).

If you want it to be something else, you'll need to give it a value with a colon and no spaces:
JavaScript:
// sets it to a value
<randomEnable:75>
// randomEnable: "75"
// use parseInt() in a plugin to translate it to a number.

// set it to an object
<randomEnable:[75,100]>
// randomEnable: "[75,100]"
// use JSON.parse() in a plugin to translate it to an object to work with.

You can see my J-Base plugin for a variety of examples on parsing notes off stuff (database/events/etc) via .meta and through regex.

I would also encourage you just... try things and see what works. Exploration/experimentation is like 50% of how I figured this kind of obscure stuff out (the other half being looking at other people's plugins to see how they did it).
 

rexie09

Villager
Member
Joined
Apr 4, 2021
Messages
26
Reaction score
10
First Language
English
Primarily Uses
RMMZ
What is circled in this image is a direct result of putting:
JavaScript:
<randomEnable>
in a note box somewhere (looks like a weapon judging by the rest of the data).

If you want it to be something else, you'll need to give it a value with a colon and no spaces:
JavaScript:
// sets it to a value
<randomEnable:75>
// randomEnable: "75"
// use parseInt() in a plugin to translate it to a number.

// set it to an object
<randomEnable:[75,100]>
// randomEnable: "[75,100]"
// use JSON.parse() in a plugin to translate it to an object to work with.

You can see my J-Base plugin for a variety of examples on parsing notes off stuff (database/events/etc) via .meta and through regex.

I would also encourage you just... try things and see what works. Exploration/experimentation is like 50% of how I figured this kind of obscure stuff out (the other half being looking at other people's plugins to see how they did it).
thanks i figured it out after asking by just doing some inspection of other plugins.
 

jade52blue

Warper
Member
Joined
Apr 3, 2021
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
Does anyone know of approaches/plugins that help with surfacing options in the RPGmaker ui itself?

I'm working on a script for triggering events via regions and i have the underlying scripts working, but im having a lot of trouble surfacing it in a useable way. What i have right now is specifying the event note to be for example: "RT-1:2-3:6" meaning "regions triggers: page 1 is triggered when player enters region 2, page 3 is triggered when player enters region 6". If a page is specified in the list, then the default trigger is ignored under the hood, if a page isn't in this list it acts normally.

I'm guessing adding a 6'th "region" event trigger to the dropdown isn't an option, but I was hoping there is some other (ideally more visual) way to select custom triggers in the IDE ui without having to replace default functionality.
Has anyone else run into / found solutions to this sort of thing?
 

Boonty

Veteran
Veteran
Joined
Oct 10, 2018
Messages
132
Reaction score
49
First Language
French
Primarily Uses
RMMV
Hey everyone.

I would like to set my Variable 3 to be the sum of the uneqquiped weapons from id 3 to 29.

Could you help me with that ? :)

Ok so I tried something on my own :

Code:
for (let i = 3; i <= 29; i++) {
gameVariables.setValue(3, $gameVariables.value(3) + $gameParty.numItems($dataWeapons[i] );
}

Sadly, the variable 3 is still 0.

What am I missing ?

EDIT : https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-mz-script-call-list.46456/post-491323

I found this message. Don't know if it is the reason for my trouble.
 
Last edited:

alltheyuriz

They System is overrated
Veteran
Joined
Sep 18, 2020
Messages
390
Reaction score
234
First Language
English
Primarily Uses
RMMZ
I would like to ask some people if they don't mind me looking over their javascripts to help me look more into how to aim it into MV/MZ not using it as a shell or templet just to see functions that work in the script of the program and what not. I would never steal anyone's work
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,274
Reaction score
674
First Language
English
Primarily Uses
RMMV
Ok so I tried something on my own :

Code:
for (let i = 3; i <= 29; i++) {
gameVariables.setValue(3, $gameVariables.value(3) + $gameParty.numItems($dataWeapons[i] );
}

Sadly, the variable 3 is still 0.
1) You're not using the proper name of the function, it's $gameVariables.setValue() and you're missing the dollar sign at the front.
2) numItems takes a BaseItem as the argument, and $dataWeapons is an array of Weapons, so that won't do anything.

The problem with what you want to do is that, normally, the engine does not track multiples of weapons and armor in the same way as items. You can see this if you buy a few, open your menu, you'll see, say, four short swords listed individually. So the engine doesn't have a built-in function to say how many of a given weapon the party has, you will have to go through all of their carried weapons and individually add them up.
Code:
var count=0;

for (var i=0; i<$gameParty.weapons().length; i++)
{
    if ($gameParty.weapons()[i].id>2 && $gameParty.weapons()[i].id<30)
        count++;
}
$gameVariables.setValue(3, count);


I would like to ask some people if they don't mind me looking over their javascripts to help me look more into how to aim it into MV/MZ not using it as a shell or templet just to see functions that work in the script of the program and what not. I would never steal anyone's work
This question is a bit confusing. The entire JavaScript of the engine is right there in your project folder for you to read, and every plugin you download for the game can be opened in an editor for you to read.
You don't need permission to read the contents of files that you own or that are publicly posted for download, so...what are you asking?
 

Latest Threads

Latest Posts

Latest Profile Posts

finished the draft of some of this dude's motions!

mc0xoB4.gif


gonna work on the drafts of the other 3 now before i put detail, need to position these rather tall sprites well on the field

waiting for the term to end so i can get more time w this :kaodes:
Vaguely toying with demon/tiefling type parts but will probably work on something else first because eventually I'm going to have to make wings and I don't feel up to it yet. In the meantime, this guy:

TestChara-15.gif

I ended up reworking the interface, and Poppet's animations so she has a wand now and waves it to fire a shot. Also I gave her a shadow. Still have to rerender other stuff with shadows but eh.... I like her new "pew pew" wand. :LZSexcite:
PSA: please stop putting the word 'Eternal' in your game titles.
RMMZ: "Simple enough for a child!"
also RMMZ: "What, you're trying to make an RPG and you didn't know about Euler angles?"

Forum statistics

Threads
113,634
Messages
1,076,317
Members
147,643
Latest member
Sataesim
Top