JavaScript questions that don't deserve their own thread

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
3,165
Reaction score
1,869
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
760
Reaction score
258
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
3,165
Reaction score
1,869
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
81
Reaction score
19
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
3,165
Reaction score
1,869
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
118
Reaction score
17
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
6,621
Reaction score
8,598
First Language
Indonesian
Primarily Uses
RMVXA
Create a thread for that, unless you ask a JS syntax, it goes here.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
760
Reaction score
258
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,100
Reaction score
567
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
6,621
Reaction score
8,598
First Language
Indonesian
Primarily Uses
RMVXA
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
3,165
Reaction score
1,869
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
760
Reaction score
258
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

Warper
Member
Joined
Dec 21, 2020
Messages
4
Reaction score
0
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
3,165
Reaction score
1,869
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

Warper
Member
Joined
Dec 21, 2020
Messages
4
Reaction score
0
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
3,165
Reaction score
1,869
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

Warper
Member
Joined
Dec 21, 2020
Messages
4
Reaction score
0
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
3,165
Reaction score
1,869
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

Warper
Member
Joined
Dec 21, 2020
Messages
4
Reaction score
0
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
110
Reaction score
83
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 Posts

Latest Profile Posts

You thought kids rooms were messy. Look at this.
Back in the house and I'm hungry
Yoshi!
DNPwhy.gif

You're using that item wrong... TwT

Trying to get the mechanics down for a cute, story-driven board game! I think I've accomplished dice movement, item effects, and activating a space's event when you land on it. Art is WIP. Hope to open a thread about the game soon!
My entire family and I have Covid... If it's this bad with the vaccine, without must be terrible. Stay safe, everyone. This thing is a doozy.

Forum statistics

Threads
118,525
Messages
1,116,629
Members
155,540
Latest member
NecroCaticGames
Top