JavaScript questions that don't deserve their own thread

Joined
Jul 8, 2021
Messages
8
Reaction score
1
First Language
English
Primarily Uses
RMMV
What are the settings on your state? If I understand correctly, states don't get removed at turn end until their counter is at 0 - that means the engine doesn't natively support the ability to have states that only last for the turn they're applied, as the minimum value you can enter for the duration is 1 (think of it as the number of full turns).

So for this to work, you'd have to use note tags or a line of code in your After Eval to make the duration of the state start at 0.

I tried adding
JavaScript:
member._stateTurns[81] = 0;
to the After Eval. The state now disappears if an actor is attacked (not 100% what I'm looking for but that's not really a problem), and that allows me to reapply the state to that actor by reusing the skill on the next turn. However, reusing the skill still won't apply the state to any other actors that were not attacked, as if the state is not properly refreshing like it does when an actor gets attacked (it does also apply to the actor that used/is using the skill, which I guess is because by that point there's been one whole turn since the initial usage of the skill).

These are the state's settings; they're fairly simple:
sowing.png

Turning off the Turn End auto-removal causes the state to not be removed at all, even though the addition to the After Eval sets the turns to zero (I assume that it doesn't check turn count if there is no auto-removal parameter). Forcing a removal through e.g. user.removeState in the state's note field is not effective.

Sorry if I'm overcomplicating this but I am stumped.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,194
First Language
English
Primarily Uses
RMMV
I tried...
You should start a new post about this, as it:
1) clearly deserves its own thread, and
2) is not actually about using JavaScript, but the functionality of a specific plugin.

As you do so, try pulling up the console in your game with F8, go to the console, and manually check actors with isStateAffected to try to verify that they in fact don't still have the state on them (as that's what would normally prevent a state from being applied).
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
102
First Language
English
Primarily Uses
RMMZ
I need to alter this so characters never use skill ID 1 or 2 when autobattling
I also need to alter this so characters always use skills with the skill type ID 2 when autobattling

Kinda stuck on where to even begin on this one.

JavaScript:
Game_Actor.prototype.makeActionList = function() {
    var list = [];
    var action = new Game_Action(this);
    action.setAttack();
    list.push(action);
    this.usableSkills().forEach(function(skill) {
        action = new Game_Action(this);
        if (skill.id !== 1 || skill.id !== 2) {
            action.setSkill(skill.id);
            list.push(action);
       };
    }, this);
    return list;
};

};
You only need to worry about this method and while I'm unfamiliar with that particular array method, all you really need to do is fork in a conditional statement that allows all skills to be added to the list that don't have an id of 1 or 2. I modified the code to show you an example of what I mean, but it has not been tested for accuracy.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
709
Reaction score
230
First Language
English
Primarily Uses
RMMV
Could someone help me set up a script call that can set a range of variables to the value of a separate range of variables?

For a bit of context, I have a range of 20 consecutive variables that contain the id's of the player's deck of trading cards. I want to back up these values into a separate batch of consecutive variables, so I can restore those values at a later time.
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
14
Reaction score
1
First Language
english
Primarily Uses
i'm trying to make a skill obtained from a weapon, using yanfly skill core, require both a specific state and a variable to be at least one what am i doing wrong?


<Custom Show Eval>

if ($gameActors.actor().isStateAffected(22) && $gameVariables.value(1) >==1) {

visible = true;

} else {

visible = false;

}

</Custom Show Eval>

with this the skill shows no matter what
 
Last edited:

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
644
Reaction score
888
First Language
German
Primarily Uses
RMMV
@cubeking1
try replacing "$gameActors.actor()" with "user"
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
299
Reaction score
375
First Language
English
Primarily Uses
RMMV
@Vis_Mage you can use a for loop if they're consecutive. Suppose that your original variables are in variables 100-119, and you want to copy them to variables 200-219. So the code would be:
Code:
for (let i = 0; i < 20; i++) {
    let origId = 100 + i;
    let copyId = 200 + i;
    $gameVariables.setValue(copyId, $gameVariables.value(origId));
}
You can just change the numbers 100 and 200 to the starting values of your own variables.
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
644
Reaction score
888
First Language
German
Primarily Uses
RMMV
@cubeking1
Ah my mistake, the problem is most likely the ">==" then, which should be ">=".

Try this notetag:

<Custom Show Eval>
if (user.isStateAffected(22) && $gameVariables.value(1) >=1) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,194
First Language
English
Primarily Uses
RMMV
if ($gameActors.actor().isStateAffected(22) && $gameVariables.value(1) >==1) {
Just to expand on ScorchedGround's reply, $gameActors.actor() is a function that requires an argument to be passed into it - the ID of the actor you want returned to you. e.g. $gameActors.actor(1)

And then >== is not a valid operator, but you were already told that.

If you're learning JavaScript to use in RPG Maker, you may find this a useful reference.
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
14
Reaction score
1
First Language
english
Primarily Uses
@cubeking1
Ah my mistake, the problem is most likely the ">==" then, which should be ">=".

Try this notetag:

<Custom Show Eval>
if (user.isStateAffected(22) && $gameVariables.value(1) >=1) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>
this works thank you very much
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
102
First Language
English
Primarily Uses
RMMZ
Edit: I figured it out.
 
Last edited:

imaginaryrose

Villager
Member
Joined
Jul 4, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
Is there a way to give an actor exp via javascript without the level up message? I know about $gameActors.actor(n).gainExp(x), but if the actor gains enough exp to level up I don't want the message window to pop up.
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
102
First Language
English
Primarily Uses
RMMZ
Is there a way to give an actor exp via javascript without the level up message? I know about $gameActors.actor(n).gainExp(x), but if the actor gains enough exp to level up I don't want the message window to pop up.
Code:
$gameActors.actors(n).shouldDisplayLevelUp = false

Can also apply to $gameParty.
 

imaginaryrose

Villager
Member
Joined
Jul 4, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
Thanks, @Arctica! I couldn't quite get it to work as a script call. It said should shouldDisplayLevelUp is not a function, but then I found the shouldDisplayLevelUp function in rpg_object.js and I figured it out from there. Thanks for the help!
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
102
First Language
English
Primarily Uses
RMMZ
That's because I made a syntax error and only noticed it just now-____-. It should've been actor and not actors.
 

imaginaryrose

Villager
Member
Joined
Jul 4, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
It's strange, but even with the edit I still couldn't get it to work.
 

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
102
First Language
English
Primarily Uses
RMMZ
Outside of typos and calling it on objects it doesn't belong to, I can only assume two things that cause that error to be thrown:

1. It's syntactically different from MZ. It's the only version I use and most of the core files wasn't changed too much if at all.

2. You missinterpreted my post to be this: $gameActors.actor(n).shouldDisplayLevel() = false

The bold part will throw the type error, because while it's a method of Game_Actor, it's not to be called as a function in this context.

In any case, glad you got working.
 

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
272
Reaction score
376
First Language
French, German
Primarily Uses
RMMZ
Shouldn't it be $gameActors.actor(n).shouldDisplayLevel = () => false; instead?
If shouldDisplayLevel is a function and you overwrite it with false, then eventually something will call false() which will throw an error, because false is not a function.

Instead, what you want is to overwrite shouldDisplayLevel with a function that returns false, which the arrow function () => false does.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,194
First Language
English
Primarily Uses
RMMV
2. You missinterpreted my post to be this: $gameActors.actor(n).shouldDisplayLevel() = false

The bold part will throw the type error, because while it's a method of Game_Actor, it's not to be called as a function in this context.
You can't just decide something isn't a function. What you typed could be used to store a reference to the shouldDisplayLevel function in a variable and call it later, but it can't change what that function returns.
Shouldn't it be $gameActors.actor(n).shouldDisplayLevel = () => false; instead?
That is more like it, if you included that as a plugin - however, my understanding of the original question is that the OP only wanted to not display level ups under specific circumstances.

So, @imaginaryrose - what do you want to do in your game? If you are always giving exp via script call and never want to display level up information, put Nolonar's line into a plugin.

But if you also have regular combat, and you want level up info there but not when you're awarding exp outside of combat, you'll need a way to control it. So, again in a plugin,
Code:
Game_Actor.prototype.shouldDisplayLevelUp = function() {
    return $gameSwitches.value(X);
};
where X is an ID of an unused switch in your game. Then you can use event/script commands to turn that switch on or off and display the level up info accordingly.
 

Latest Threads

Latest Posts

Latest Profile Posts

you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.
Been sick with a stomach virus for seven days now. Not going to work tomorrow because I'm still contagious according to my doctor.
Much as I love my job, I really hate playing "office politics". It would be nice if I didn't have to pretend to be someone else all day long.
I wanna get back into showing off Battlers and other assets I create again. But i'm always haunted by the "It's not good/realistic enough" voices that keep me from doing so.

Maybe I should get back to it, I did enjoy showing off whatever I came up with!

Forum statistics

Threads
115,958
Messages
1,094,380
Members
151,220
Latest member
Dolton
Top