JavaScript questions that don't deserve their own thread

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
Is there a script call that I can use to check each variable within a convective range of IDs (such as variables 800-872) to see if they are greater than 0, and if so, add the value of variable 873 to them?
I'm confused by your wording as to whether you want to add the value of 873 to each of those other variables IFF they are greater than 0; or if you want to get one number that is the sum of all of those?

Either way, you'd just access the variables array directly: $gameVariables._data[index]

So you can make a loop that goes through that and does whatever you intended to say, or use the JavaScript inherent array functions, whatever.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
775
Reaction score
278
First Language
English
Primarily Uses
RMMV
I'm confused by your wording as to whether you want to add the value of 873 to each of those other variables IFF they are greater than 0; or if you want to get one number that is the sum of all of those?

Either way, you'd just access the variables array directly: $gameVariables._data[index]

So you can make a loop that goes through that and does whatever you intended to say, or use the JavaScript inherent array functions, whatever.
The first one is what I was hoping to do, add the value of 873 to each variable from within the range that had a value greater than 0. Although, both would honestly be really helpful to know.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
The first one is what I was hoping to do, add the value of 873 to each variable from within the range that had a value greater than 0. Although, both would honestly be really helpful to know.
I'd suggest you do some JavaScript tutorials (I like w3schools, but there are a bunch of sites). There's nothing wrong with asking questions, but you've been asking a bunch and most of them (like this) are pretty basic - so at some point it takes less time to just learn than to ask the question :stickytongue:

So you just do a basic loop.
Code:
for (var i=800; i<873; i++)
{
    if ($gameVariables._data[i]>0)
        $gameVariables._data[i]+=$gameVariables._data[873];
}

As far as adding them all up, that's even more basic...
Code:
var sum=0;
for (var i=800; i<=873; i++)
    sum+=$gameVariables._data[i];
 

raffle

Veteran
Veteran
Joined
Oct 25, 2020
Messages
105
Reaction score
42
First Language
English
Primarily Uses
RMMV
Hey :) So I know I can use (this._eventId) to get the id of the current running event, but is there something similar to get the ids of all events in the current map so that I could affect them all at once to display an effect for example?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
Hey :) So I know I can use (this._eventId) to get the id of the current running event
Note that this is a JavaScript reserved word, so that only works when you're writing code executed by an event.
is there something similar to get the ids of all events in the current map
The events for the current map are an array returned by $gameMap.events()

You can do anything to that that you can do to an array. If that's not helpful enough for your skill level, you should start a new thread describing exactly what you're trying to accomplish and we'll see what we can do.
 

matgraz

Veteran
Veteran
Joined
Feb 4, 2018
Messages
128
Reaction score
22
First Language
Portuguese
Primarily Uses
RMMV
Is there anyway to set a % on 'add state x' action on YEPs action sequences?
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,155
Reaction score
10,473
First Language
Indonesian
Primarily Uses
N/A
Create a thread for that, unless you ask a JS syntax, it goes here.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
775
Reaction score
278
First Language
English
Primarily Uses
RMMV
Quest question, I'm currently using those script call to force use an item on a actor who's ID is determined by a variable. (Code originally found here: https://forums.rpgmakerweb.com/inde...e-item-effect-use-on-map-in-main-menu.118167/)

Would someone be able to help me adjust it, to make it target all party members instead?

Code:
var itemId = $gameVariables.value(21), actorId = $gameVariables.value(22);
(function(v,i,t,a,c,u) {
if (i = $dataItems[+v || 0]) {
u = $gameParty.members()[$gameActors.actor(actorId).index()];
a = new Game_Action(u); a.setItemObject(i);
t = i.scope === 7 ? [u] : a.makeTargets();
for (n in t) c = c || a.testApply(t[n]);
if (u.canUse(i) && (i.scope === 0 || c)) { u.useItem(i);
  $gamePlayer.requestAnimation(i.animationId);
  a.apply(t[n]); a.applyGlobal();
}}})(itemId);
 

dopan

Veteran
Veteran
Joined
Mar 27, 2020
Messages
1,298
Reaction score
691
First Language
German
Primarily Uses
RMMV
thats probably a stupid question, but what does " !! " mean?

i know that a single "!" means "not"

but i was reading in a plugin code where " !! " was used
(screenshot)
Screenshot_3.png
.. and i am not sure if thats an typo mistake and does the same as "!" or if it means something else..
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,155
Reaction score
10,473
First Language
Indonesian
Primarily Uses
N/A
Apparently, it is to convert any variable to a boolean value (true or false).
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
Would someone be able to help me adjust it, to make it target all party members instead?
Does it not do it automatically if you set the scope of the item to All Allies?

While you've brought it up, what the heck is this saying?
Code:
if (i = $dataItems[+v || 0])
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
775
Reaction score
278
First Language
English
Primarily Uses
RMMV
Running the above code using an item that is set to target all allies still only seems to affect the actor that the code uses the item on.

As for that bit of code, I'm not actually quite sure. Besides modifying it so the item and actor ID's are determined by the value of a variable, I got this bit of code from the linked post.
 

Flame_Effigy

Villager
Member
Joined
Dec 21, 2020
Messages
15
Reaction score
5
First Language
English
Primarily Uses
RMMV
This is probably really obvious but

Any given actor in a game I'm working on will wind up having eight skills total, and I'm looking for a way to make a variable for each of those skills to use in dialogue, choices, text, etc.

Specifically for the currently known skills.
Example, Character A knows skills 1, 2, 3, 4, 5, 6
var 1 should be 1
var 2 should be 2, etc
But if Character A instead knows skills 3, 4, 5, 6
var 1 should be 3
var 2 should be 4, etc

So how exactly would I got about getting, for example, the first known skill that actor 1 has.
I believe I have to do something with $gameActors.actor(1).skills()) but I'm not quite sure how to do it.

Thanks.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
Any given actor in a game I'm working on will wind up having eight skills total, and I'm looking for a way to make a variable for each of those skills to use in dialogue, choices, text, etc.
How you do this depends a lot on how your skills work. Are you just using the default "class X gets skill Y at level Z" system, or something else?

Are the actors the same class throughout the game, or can they change? If yes, does that affect their skills?

What do you consider to be "the first known skill?" Is it the default skill system and it's the earliest-level skill they learned? Is it the one with the lowest skill ID? Do you have some kind of skill equip system and it's whatever is in skill slot 1?
 

Flame_Effigy

Villager
Member
Joined
Dec 21, 2020
Messages
15
Reaction score
5
First Language
English
Primarily Uses
RMMV
How you do this depends a lot on how your skills work. Are you just using the default "class X gets skill Y at level Z" system, or something else?

Are the actors the same class throughout the game, or can they change? If yes, does that affect their skills?

What do you consider to be "the first known skill?" Is it the default skill system and it's the earliest-level skill they learned? Is it the one with the lowest skill ID? Do you have some kind of skill equip system and it's whatever is in skill slot 1?
Class gets Y skill at Z level.
No skills changed by class.
Earliest skill they learned I suppose. Lowest skill ID would be fine too.
If I did have a skill equip system I would want equipped skills excluded. Would it be possible to only check for a specific type of skill in that instance?

The reason I'm trying to do it this way is actors will lose skills of their choice through dialogue choices so setting up the variables to be dependent on the actors' currently known skills seemed like the right way to go.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
Class gets Y skill at Z level.
Earliest skill they learned I suppose.
The easiest way to do that would be to iterate through $dataClass[the actor's class].learnings[] but this won't work well for you since you'll be having them forget skills later
If I did have a skill equip system I would want equipped skills excluded. Would it be possible to only check for a specific type of skill in that instance?
Look up JavaScript's array.filter()
The reason I'm trying to do it this way is actors will lose skills of their choice through dialogue choices so setting up the variables to be dependent on the actors' currently known skills seemed like the right way to go.
This sounds less like a specific, minor JavaScript question, and more like a new thread you should start to figure out how to set up this system.

Before doing so, you need to determine exactly how you want your entire skill system to work, because you have a number of places where you seem uncertain or undecided, so no one can help you do a specific thing until you've decided upon it.

I would suggest looking at calling common events when leveling up to add any new skills to your variables, and then whatever event you use to discard a skill for a new one should be able to modify the appropriate variable then.
 

Flame_Effigy

Villager
Member
Joined
Dec 21, 2020
Messages
15
Reaction score
5
First Language
English
Primarily Uses
RMMV
The easiest way to do that would be to iterate through $dataClass[the actor's class].learnings[] but this won't work well for you since you'll be having them forget skills later
Okay so just for my sake. The real meat of my original question is that I'm looking to turn a character's currently known skills into variables in a standard level up system. The rest of it is unimportant at the moment.

The best way to go about this would be to set up a common event on level up and alter the variables there?
I was under the impression that $gameActors.actor(1).skills()) returned all the currently known skills of actor 1 as an array but when I try to reference them I just get object Obejct in the message boxes
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,563
Reaction score
5,328
First Language
English
Primarily Uses
RMMV
I was under the impression that $gameActors.actor(1).skills()) returned all the currently known skills of actor 1 as an array but when I try to reference them I just get object Obejct in the message boxes
Yes, it does. I don't know how you're referencing them as you don't provide an example of your code, but for example: $gameActors.actor(1).skills()[0] will return the first skill actor ID 1 learned (before any messing with forgetting and learning more stuff).

Note that just looking at a skill is going to give you exactly what you saw, as a skill is an entire data type. You would want to look at its id or its name via the appropriate member variable (e.g. $gameActors.actor(1).skills()[0].name ).

You may find this reference useful in your endeavors:

The best way to go about this would be to set up a common event on level up and alter the variables there?
The reason I say that is so that you can just have a list of variables for each character with the name of the skill stored, which lets you use regular text escape codes to refer to them. Otherwise, every time you want to reference that list you'll have to be using script calls like the above instead of just, say, \v[0]
 

Flame_Effigy

Villager
Member
Joined
Dec 21, 2020
Messages
15
Reaction score
5
First Language
English
Primarily Uses
RMMV
Yes, it does. I don't know how you're referencing them as you don't provide an example of your code, but for example: $gameActors.actor(1).skills()[0] will return the first skill actor ID 1 learned (before any messing with forgetting and learning more stuff).

Note that just looking at a skill is going to give you exactly what you saw, as a skill is an entire data type. You would want to look at its id or its name via the appropriate member variable (e.g. $gameActors.actor(1).skills()[0].name ).

You may find this reference useful in your endeavors:
Thank you very much that is what I needed to know.
 

MarxMayhem

Veteran
Veteran
Joined
Apr 17, 2020
Messages
251
Reaction score
256
First Language
Filipino
Primarily Uses
RMMV
If I am understanding it correctly, if I have multiple instances of "<variable> *=", then as long as each instance of <variable> is a number, it will result with a multiplicative product of those numbers?
(e.g. three instances of <variable> has 0.9, so <variable> = 0.9 * 0.9 * 0.9 = 0.729)?
 

Latest Threads

Latest Profile Posts

Someday, I hope they make a game where 95% of the animation budget went to turning valves and opening door animations, leaving every other animation looking like a CDI zelda cutscene.
programming at 12 years old: "I love how it works!"
programming at 18: "I love that it works."
programming at 25: "I love why it works."
programming at 30: "I love when it works."
programming at 50: "How did this work?"
Why can't I insert picture in this profile post? Only insert image -> by URL. No option to upload from my pc?
Trying out a new Battle Ui.
BattleUI.png
And.... I couldn't help myself. I linked my card game Lore and Concepts back to my RPG Maker game and made them take place in the same universe. I think that means I need to get back to work on my RPG Maker Game. There's obviously a story here my brain wants to tell.

Forum statistics

Threads
129,758
Messages
1,204,887
Members
170,846
Latest member
suball
Top