JavaScript questions that don't deserve their own thread

Boonty

Veteran
Veteran
Joined
Oct 10, 2018
Messages
155
Reaction score
57
First Language
French
Primarily Uses
RMMV
@Arthran Thanks for your explanations. You saved me a lot of time with your intervention :)
 

emelian65

Veteran
Veteran
Joined
Sep 13, 2015
Messages
201
Reaction score
66
First Language
Spanish
Primarily Uses
RMMV
It's been a long while since the last time I actually did anything in this, but I'm trying actually to make a living out of this, somehow hahaha, everyone can dream right?.

Anyway I'm sure I already asked this, like several years ago, but I need help again.

By using Yanfly Buff & States Core I'm able to create the stacks, my character is basically able to stack a state to deal more damage or heal more with his skills, I was able to do that simply by using and modifying Stockpile, Spitup and Swallow tips and trick also from Yanfly.

The only problem is I want the stacks to reduce, not disappear but to reduce, so like his first attacking skill reduces the stack by 15 points and the second by 25 points and so on, but I'm lost on how to reduce the stacks and make it show in the stack counter of the state... please help T_T

<After Eval>

// Reduce Water

user._Water -= 15;

user.setStateCounter(8, user._Water);

</After Eval>

I'm using this one in the attacking skill but I'm pretty sure that it's very wrong as it's not doing anything to the stack counter at all... so... help?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,096
Reaction score
3,248
First Language
English
Primarily Uses
RMMV
I'm sure I already asked this, like several years ago, but I need help again.
I suggest you start a new thread with this, and make sure to include every notetag of each skill or state that's involved. Screenshots especially of the state would be a good idea, too.

The two code statements you show here appear to be correct, so obvious points of failure would be if the ._Water variable isn't actually defined, or 8 isn't the correct ID for the state.

For what it's worth, this just came up in another thread today - there's not actually any reason to be tracking both a variable on the actor and a state's counters. The Buffs and States plugin provides all the functions you need to just work with the counters instead of managing two different things.
 

emelian65

Veteran
Veteran
Joined
Sep 13, 2015
Messages
201
Reaction score
66
First Language
Spanish
Primarily Uses
RMMV
Thank you for telling me, I really thought it wasn't something difficult that needed its own thread, I don't know exactly how I got it to work, but now is working properly so I'm good on using the state as a resource, my other question may need it's own thread however so I'll see if I can make a thread for it.

Even then thank you for your time.
 

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,224
First Language
English
Primarily Uses
RMMV
Quick JS question:

If we have something that returns null, would an if statement like the following return true or false?

var stuff = (something that returns null);
If (stuff) {
//code
}

Edit: Nvm, it's falsy.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,865
Reaction score
12,410
First Language
English
Primarily Uses
RMMZ
I have an enemy drop which, when the player opens it, gives a slightly random reward. In order to do this, I use a common event which runs the random variable etc. for each individual instance of this item.

However, once you have opened the drop and seen what you've got, it sends you back to the map. If you have another similar drop (highly likely) you have to press esc to get back to the Main Menu, then Item. Boring. If you have several it becomes quite tedious.

Is there a bit of code which will force open the Item menu?
I thought of:
  • using a second variable to count how many of the item the player has,
  • then a conditional with the count being equal to or greater than 2 so that when the first one has been opened there is a reason for re-opening the menu
  • tell the player how much they got with the first instance
  • force open the Item Menu
  • the common event then runs again.
  • Once the count is less than 2 (i.e. only one left) then the 'else' branch just tells the player how much they got and finishes.
Is this possible?
Thank you.
 

BloodletterQ

Chaotic Neutral Assassin
Veteran
Joined
Aug 15, 2012
Messages
1,596
Reaction score
1,228
First Language
English
Primarily Uses
N/A
So I'm trying to figure out just how can I hide a certain option in Visustella's Options Core while I'm accessing it from the title screen.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,865
Reaction score
12,410
First Language
English
Primarily Uses
RMMZ
I need various things to happen when actor 3's HP falls below 35%.
I used the following script call in a conditional branch:

Code:
$gameActors[3].hpRate <= 0.35

However, the console tells me that hpRate doesn't exist in JS (that's me just trying to convert hp_rate).

Could someone correct my code for me.
Thank you.
 

TSR

The Northern Frog
Veteran
Joined
Nov 14, 2019
Messages
472
Reaction score
560
First Language
French
Primarily Uses
RMMZ
Hello @Kes ,
hpRate is a method.
Hence: $gameActors[3].hpRate() <= 0.35

Regards.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,865
Reaction score
12,410
First Language
English
Primarily Uses
RMMZ
@TSR Thank you for that.
I think I shall have to train myself up to put brackets in if something isn't working.
 
  • Like
Reactions: TSR
Joined
Jul 11, 2022
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hello! I'm using this Community Lighting plugin for RMMV and can't figure out how to turn the Player radius on and off using an event. I use lights on all of my maps so I always have Player radius set to 0, but I want my character to walk into a room that is completely dark except for a small torch she is holding. Similar to using a flashlight effect, but I don't want to use the beam command since she's holding a torch.

I'm sure the answer is obvious but I don't have any JS experience. How can I change the Player radius to equal 200 from a switch-activated event?

Thank you!
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
406
Reaction score
232
First Language
English
Primarily Uses
RMMV
I have an enemy drop which, when the player opens it, gives a slightly random reward. In order to do this, I use a common event which runs the random variable etc. for each individual instance of this item.

However, once you have opened the drop and seen what you've got, it sends you back to the map. If you have another similar drop (highly likely) you have to press esc to get back to the Main Menu, then Item. Boring. If you have several it becomes quite tedious.

Is there a bit of code which will force open the Item menu?
I thought of:
  • using a second variable to count how many of the item the player has,
  • then a conditional with the count being equal to or greater than 2 so that when the first one has been opened there is a reason for re-opening the menu
  • tell the player how much they got with the first instance
  • force open the Item Menu
  • the common event then runs again.
  • Once the count is less than 2 (i.e. only one left) then the 'else' branch just tells the player how much they got and finishes.
Is this possible?
Thank you.

I'm very rusty with RM makers, but as no one has jumped on this I might as well have a bash. You can definitely use a script in the event you define to open the item scene

Code:
SceneManager.push(Scene_Item);

In the event the player chooses not to use another item though, hitting exit would take them back to the map rather than to the main menu, so it may be better to push Scene_Menu first eg.

Code:
SceneManager.push(Scene_Menu);
SceneManager.push(Scene_Item);

In either case, you won't open the item select window. It will be the category select window (the one where you pick item/weapon/armor etc), which is better than nothing I suppose. There is code you could use to open the item menu and select the item in question but as far as I recall this won't execute properly in an event script command as events run on the map and the script needs to run while in the item scene.

You might have more luck just having your common event show choices and ask the player if they want to use another of the item if they have any leftover.
 
  • Like
Reactions: Kes

emelian65

Veteran
Veteran
Joined
Sep 13, 2015
Messages
201
Reaction score
66
First Language
Spanish
Primarily Uses
RMMV
Another question, A bit related to the use of Buff & States core again.

I'm using this code.

<Custom Apply Effect> user._miragestacks = user.miragestacks || 0; user._miragestacks += 1; user._miragestacks = Math.min(user._miragestacks, 3); user.setStateCounter(10, user._miragestacks); </Custom Apply Effect> <Custom React Effect> if (!this.isRecover() && value >= 0) { value = 0; defender._miragestacks -=1; defender.setStateCounter(10, defender._miragestacks); if (defender._miragestacks < 1) { defender.removeState(10); } } </Custom React Effect>

What it should do is, allow for the state to stack up to 3 stacks of it, (basically, stockpile from tips and tricks but with a different name), then when the defender is hit(the skill has to hit and not miss) one stack should be removed, if the value of the stacks is then 0, the state should be removed, the state does protect from damage, and goes away, but for some reason, the skill doesn't stack up the state, so I cannot confirm whether or not the stacks are reduced.

The skill is a target all skill that applies the mirage state(state 10 in this case), I thought that maybe changing all the users in the <custom apply> for target._miragestacks would maybe fix it if it was the target scope the one causing the problem but it doesn't seem to have helped at all.

So... any suggestions?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,096
Reaction score
3,248
First Language
English
Primarily Uses
RMMV
for some reason, the skill doesn't stack up the state
What exactly does this mean?

Do you not see the counters appear on the state icon at all? That's probably a plugin parameter issue.

Do you see the counter but it doesn't change when you use the skill more times? What number does it show?

You might make this a bit simpler by using the functions Yanfly provides in the documentation rather than adding a variable to the user:
Code:
if (!user.getStateCounter(10))
{
    user.setStateCounter(10, 0);
    user.clampStateCounter(10, 0, 3);
}
user.addStateCounter(10, 1);

The problem with your setup is if you finish battle with that state still having counters, I don't see how the variable on the user would be reset. So the next time you use the skill, you could start with additional stacks on it.
 

emelian65

Veteran
Veteran
Joined
Sep 13, 2015
Messages
201
Reaction score
66
First Language
Spanish
Primarily Uses
RMMV
What exactly does this mean?

Do you not see the counters appear on the state icon at all? That's probably a plugin parameter issue.

Do you see the counter but it doesn't change when you use the skill more times? What number does it show?

Ok so the skill applies the state, the character gets the state with a Counter of 1(the number shows in the state and yes this is not the turn remaining as the state doesn't go away on its own yet), if I use the skill again then it doesn't increase said counter all. (For testing I removed the state removal condition, and the state can decrease all the way to a negative number, 1 to 0 to -1, and then I can increase the number but it doesn't increase past one...)


Code:
if (!user.getStateCounter(10))
{
    user.setStateCounter(10, 0);
    user.clampStateCounter(10, 0, 3);
}
user.addStateCounter(10, 1);

Ok I should put this one in the custom apply right instead of using theother ones, then in the react what should be the code to reduce 1 stack?

Like this:
Code:
defender.StateCounter(10) -= 1

The other issue I have is that this state can also be applied to allies, so far when in battle the custom variable seems to be created on its own for each character(if a character gets hit only that character counter is decreased instead of lowering all of them), So that makes me a bit weary of the user. should I leave it like that or add target. instead.

Regarding the variable if I end the battle with stacks... I don't know to be honest I guess your code would make it better right. I'll test it. and let you know, thank you for your time.

Edit: Test your code, without changing it at all and putting it in the Custom Apply Effect, the skill stacks now but it goes past 3, so the clamp is not working, also I changed the Custom react to this:

<Custom React Effect> if (!this.isRecover() && value >= 0) { value = 0; defender.addStatecounter(10, -1); defender.setStateCounter(10, 0); if (defender.getStateCounter(10) < 1) { defender.removeState(10); } } </Custom React Effect>

And is not lowering the counter when hit. TT_TT I'm sure I'm doing something wrong but I don't know where...
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,096
Reaction score
3,248
First Language
English
Primarily Uses
RMMV
The other issue I have is that this state can also be applied to allies, so far when in battle the custom variable seems to be created on its own for each character(if a character gets hit only that character counter is decreased instead of lowering all of them)
Yes, there's nothing in this code that could allow you to change the counters on multiple people at the same time. You would have to intentionally loop through the party members and adjust each one.
So that makes me a bit weary of the user. should I leave it like that or add target.
Somewhat unintuitively, they are the same. There's no difference between using user or target, the only difference is origin.
Edit: Test your code, without changing it at all and putting it in the Custom Apply Effect, the skill stacks now but it goes past 3, so the clamp is not working
I misunderstood from the documentation how the clamp worked. I thought it was a setting the state would remember, but it's something that is done when you execute it.

So you can change the Custom Apply Effect to:
Code:
if (!user.getStateCounter(10))
    user.setStateCounter(10, 0);
user.addStateCounter(10, 1);
user.clampStateCounter(10, 1, 3);
also I changed the Custom react to this...And is not lowering the counter when hit. I'm sure I'm doing something wrong but I don't know where
You're doing at least a bit of logic wrong, although it should still result in things happening.

I also suggest you try to get into good indenting habits with your code, it makes it easier to read and see where things go.

Code:
defender.addStatecounter(10, -1);
defender.setStateCounter(10, 0);
Right here, why are you counting down the counters by one just to blow all the stacks and set it to 0?

And in your first conditional, do you really want it to waste a charge if they get hit for 0? I'm not changing it, but it's a logic question.

Anyhow, making that change:
<Custom React Effect> if (!this.isRecover() && value >= 0) { value = 0; defender.addStatecounter(10, -1); if (defender.getStateCounter(10) < 1) { defender.removeState(10); } } </Custom React Effect>
This looks like it should work. Is the damage getting correctly set to 0?

If it doesn't work at all, you should check that your plugins are in the correct order and such.
 

emelian65

Veteran
Veteran
Joined
Sep 13, 2015
Messages
201
Reaction score
66
First Language
Spanish
Primarily Uses
RMMV
Anyhow, making that change:

This looks like it should work. Is the damage getting correctly set to 0?

If it doesn't work at all, you should check that your plugins are in the correct order and such.

The first one finally works, it adds to the counter up to 3 and no longer goes past 3, however the second one, definitely is not reducing the counters, the damage return is 0 when the state is on, and the damage is normal when the state is gone, but the counter doesn't get lowered in fact if the character is hit while the state is at 1 it remains as it is instead of being removed. as it was doing before but before I was using the custom variable...

Edit: I decided to go back to my original code, found a couple of novice errors, user.miragestacks instead of user._miragestacks, and also no space between the -=1, now it seems to be working. I still need to do more test in-game instead of only in troop.

However now I'm wondering why the one you provided is not working... it should but for some reason it isn't, maybe the addStateCounter is not working as intended???
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,096
Reaction score
3,248
First Language
English
Primarily Uses
RMMV
found a couple of novice errors, user.miragestacks instead of user._miragestacks
That would do it.
and also no space between the -=1
That doesn't do anything. JavaScript doesn't care about spaces between operators.
However now I'm wondering why the one you provided is not working... it should but for some reason it isn't, maybe the addStateCounter is not working as intended???
If you got it working, it doesn't really matter. Just be careful, if you're going back to the method using a user variable, of what I said in my first reply about making sure you clear it.
 

retrofiction

Veteran
Veteran
Joined
Oct 26, 2015
Messages
49
Reaction score
21
First Language
German
Primarily Uses
RMMV
Hey everyone. I guess this one is simple, but I can't figure it out quick enough..
How do I check if an array does NOT include a specific value? I want to negate this statement:

JavaScript:
if ($gameVariables.value(140).includes('28'))
{
do something
}
 

Latest Threads

Latest Posts

Latest Profile Posts

Food for thought. Factorio: Spaghetti belts make your factory inefficient as you fight for space constantly. Satisfactory: Spaghetti belts and massive clipping is the most efficient way to run your factory since it's the shortest distances.
ScreenShot_8_19_2022_8_51_4.png
Both Mike and Ray here are in a "HYPE!" state after Mike uses "Wild Party", which also heals everyone. they'll do more damage and counter more often, but defense is lower along with hit rate.
WHEEL3.gif
Ooker spookers and fun attack mechanics! What a Friday!
Not today... Not today...
I guess I should send my CV to Hasbro. I've made Monopoly cheaters edition more fun and challenging. I've developed custom cheats and chest/chance cards for it. And I've cleared many nightmares through my cards and rules.

Forum statistics

Threads
124,708
Messages
1,165,420
Members
163,521
Latest member
Balalaika
Top