JavaScript questions that don't deserve their own thread

Veeter

Villager
Member
Joined
Nov 12, 2020
Messages
14
Reaction score
0
First Language
English
Primarily Uses
RMMV
Edit:
[Redacted] Outdated info.
 
Last edited:

Dustin2022

Warper
Member
Joined
Oct 16, 2022
Messages
4
Reaction score
0
First Language
German
Primarily Uses
RMMZ
The Variable is on 1, no matter how often you use the item.
I mean \V[3], sorry for that.
The goal is to change the window and textbox color, for example you buy "Window Color (Yellow)" and use it. The window and textbox color turns to yellow.

By "Window Color (Black)" to black, by "Window Color (Blue)" to blue and so on.
 

eomereolsson

Regular
Regular
Joined
Sep 29, 2021
Messages
582
Reaction score
508
First Language
German
Primarily Uses
RMMV
@Dustin2022 I advise you to make your own thread and provide screenshots, because it is not really clear to me what your setup is. You say your event has "no trigger". Is it then maybe just not running?

An alternative approach would be to use some more common events and hard code for every item with a different common event which window color it should be.

Finally I personally would advise against gateing what are essentially display options behind ingame currency. But it is your game so you do you.

@Veeter I also advise you to make your own thread. This does not seem like a general javascript question to me, but rather one where the answer requires knowledge of a specific (and apparently rather complex) plugin.
 

Narch

Regular
Regular
Joined
Jan 13, 2017
Messages
88
Reaction score
11
First Language
French
Primarily Uses
Hello.

Anybody knows a simple tutorial/lesson to learn the difference between primitives and references variables?
I read something explaining objects and references to them, but it's not clicking in my head. If you have maybe tips on what to learn BEFORE objects so I can grasp enough fundamentals.

Cheers.
 

eomereolsson

Regular
Regular
Joined
Sep 29, 2021
Messages
582
Reaction score
508
First Language
German
Primarily Uses
RMMV
The difference is that primitive variables contain the actual data, while complex ones only contain a pointer to an area in the computer's memory.
JavaScript:
let x = 5;
let y = x; //the actual value 5 gets assigned
y = 3;
console.log(x); //still 5
console.log(y); //now 3

let a = {foo:'bar', bar:'foo'};
let b = a; //the actual value in a still gets copied to b
//but since the actual value is only a pointer to where the object is stored, a and b point to the same object.
b.foo = 'foo';
console.log(a); //even though we changed b.foo, now a.foo is also 'foo'
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,100
Reaction score
1,601
First Language
English
Primarily Uses
RMMZ
Hello.

Anybody knows a simple tutorial/lesson to learn the difference between primitives and references variables?
I read something explaining objects and references to them, but it's not clicking in my head. If you have maybe tips on what to learn BEFORE objects so I can grasp enough fundamentals.

Cheers.
Putting it simply, you can look at a primitive as a type of variable that only holds one value at any given time. For example, a number variable can only hold one number at any given time, so it is a primitive. The same goes for a boolean variable, as it can only hold either true or false at any given time--never both. In JavaScript, strings are also considered primitives.

You can look at non-primitives as a type of variable that can hold multiple values at the same time. For example, an array of numbers can hold billions of different numbers at the same time, so it's not a primitive. An object can contain all kinds of different values, and it can even contain functions, so it's not a primitive either.

As eomereolsson demonstrated, when you copy a primitive variable, it will make a copy of the actual value that is stored in the variable. So then the original variable and the copy are pointing to two distinct locations in memory, and any changes you make to one has no affect on the other.

However, since a non-primitive variable might contain billions of different primitives, it would be slow and inefficient to copy the entire structure, so instead, it will just copy the memory address that points to where that data is stored. This means that both the original and the "copy" are technically accessing the same location in memory, so any changes made to the data in one will also affect the other.
 

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,729
First Language
English
Primarily Uses
RMMZ
If the Math.floor() function always rounds down, what rounds up?
Thanks.
 

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,729
First Language
English
Primarily Uses
RMMZ
@ATT_Turan oh no! I was thinking to myself, purely and entirely as a joke, that if it's floor one way it must be ceiling the other, and it is! Though abbreviated.

Thank you. Most helpful.
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
29
Reaction score
5
First Language
english
Primarily Uses
hi im using yanfly buffs and states core to to create a stacking block state that is removed one by on per hit but the counter is not ticking down can someone tell me what i am doing wrong?
<Custom Apply Effect>

// Default the stockpile stacks to 0.

user._stockpile = user._stockpile || 0;

// Increase the stockpile stack by 1

user._stockpile += 1;

// Cap the stockpile stack at 3

user._stockpile = Math.min(user._stockpile, 3);

// Update the state counter for the stockpile stack

user.setStateCounter(stateId, user._stockpile);

</Custom Apply Effect>

<Custom Respond Effect>
user._stockpile -= 1;

user.setStateCounter(stateId, user._stockpile);

if (user._stockpile = 0){
user.removeState(stateId)
}
</Custom Respond Effect>
thank you
 

DrBuni

Regular
Regular
Joined
Dec 27, 2020
Messages
234
Reaction score
143
First Language
.
Primarily Uses
RMMV
Edit: Let me know if this isn't the right place. I can start a thread for my question if so.

I am trying to change how buffs, debuffs, and elemental rates are handled in my game. I am not a fan of % buffs, preferring flat buffs instead. Now the engine itself doesn't seem to offer a straightforward way to change this, but I found this in YEP_BuffsStatesCore:

Buff formula: this._buffs[paramId] * 0.25 + 1.0

If I remove the "* 0.25", leaving the formula as "this._buffs[paramId] + 1.0 or "this._buffs[paramId] + 0.1", would that mean a buff would add 1 point to the respective stat? I really struggle to understand formulas but I am trying to learn.

Alternatively, in YEP_BaseParamControl, there are many entries such as the MaxHP formula: (base + plus) * paramRate * buffRate + flat
According to the documentation, base is the HP of the actor. Plus is whatever value is added by equipment. ParamRate is "the rate altered by the traits found within the various database objects". buffRate is a "variable calculated based on the number of buffs or debuffs stacked".

My question is, how do I simplify this formula, considering my game doesn't feature equipment (it is a really simple game mechanically), and I want to ditch percentile in buffs? I get that this isn't enough information to give an informed response on a formula, and ultimately it is my job to design the game, but I am really trying to learn by bouncing ideas with others.

How does "base + paramRate + flat" sound? If I am not missing anything, that means the formula considers the actor's health, some extra stuff based on traits (which I guess refers to stuff like elemental resistances and weaknesses, I will cross that bridge later) and a flat buff that will be defined in skills and such. Right?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,293
Reaction score
9,302
First Language
English
Primarily Uses
RMMV
hi im using yanfly buffs and states core to to create a stacking block state that is removed one by on per hit but the counter is not ticking down can someone tell me what i am doing wrong?
Why are you using this second user._stockpile variable? If you're also using state counters, everything you're doing with the stockpile variable can just be done with the counters directly...I don't see the point of messing with two different things.

Aside from that, your error is this line:

if (user._stockpile = 0){
That line is setting the stockpile variable equal to 0. If you're trying to check whether it is equal to 0, that's two equal signs: if (user._stockpile==0)

I am trying to change how buffs, debuffs, and elemental rates are handled in my game.

Buff formula: this._buffs[paramId] * 0.25 + 1.0

If I remove the "* 0.25", leaving the formula as "this._buffs[paramId] + 1.0 or "this._buffs[paramId] + 0.1", would that mean a buff would add 1 point to the respective stat?
No. For one, 1 and 0.1 are completely different numbers (I know that's obvious, and I don't intend it to come across as snarky, but you typed them both as ideas :stickytongue:).

For another, that's not how buffs work in RPG Maker. They aren't additive, they're multiplicative - the buff formula is multiplied by your base parameter value.

So if you have two layers of ATK buff on, and your ATK is 25, this._buffs[paramId] is going to be 2, and the formula's result of 1.5 is what your ATK is multiplied by.

In order to do what you want, you could not use buffs. Use states with a plugin such as Quasi Param Plus that allows you to attach flat values to states (and Yanfly's Buffs and States already allows you to stack states like buffs if you want).

Or...

Alternatively, in YEP_BaseParamControl, there are many entries such as the MaxHP formula: (base + plus) * paramRate * buffRate + flat...My question is, how do I simplify this formula, considering...I want to ditch percentile in buffs?
You simply make it add the buffRate instead of multiply it.

How does "base + paramRate + flat" sound? If I am not missing anything, that means the formula considers the actor's health, some extra stuff based on traits (which I guess refers to stuff like elemental resistances and weaknesses, I will cross that bridge later) and a flat buff that will be defined in skills and such. Right?
No, not quite right. You don't want to mess with the paramRate, that's nothing to do with elemental anything, we're talking about parameters. If you go into an Actor, Class or State, one of the traits you can select is Parameter and it's a multiplier.

Just change the part of the formula that you actually want to change - the buffs.
Code:
(base + plus) * paramRate + buffRate + flat

Then you'd do what you proposed above, making the Buff formula be this._buffs[paramId] and it will add 1 point for each stack of buff.
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
29
Reaction score
5
First Language
english
Primarily Uses
thank you for the help but the counter is still not counting down when the user is hit by an attack. thank you for resolving the issue i would end up with next though thank you
Why are you using this second user._stockpile variable? If you're also using state counters, everything you're doing with the stockpile variable can just be done with the counters directly...I don't see the point of messing with two different things.

Aside from that, your error is this line:

if (user._stockpile = 0){
That line is setting the stockpile variable equal to 0. If you're trying to check whether it is equal to 0, that's two equal signs: if (user._stockpile==0)
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,293
Reaction score
9,302
First Language
English
Primarily Uses
RMMV
thank you for the help but the counter is still not counting down when the user is hit by an attack.
You are also repeatedly using the variable "stateId" but that should be a number - the ID of the state.
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
29
Reaction score
5
First Language
english
Primarily Uses
You are also repeatedly using the variable "stateId" but that should be a number - the ID of the state.
i am using the correct state number the one i originally put here a was a blank version i made so when i was working on the skill
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,293
Reaction score
9,302
First Language
English
Primarily Uses
RMMV
i am using the correct state number the one i originally put here a was a blank version i made so when i was working on the skill
Okay...it makes the most sense to post the current actual code you're using. Otherwise, how are we to know there isn't some other little change that's causing your problems?

I'm going to get rid of the extra variable stuff and just use the state counter commands to make this easier to follow. As before, you'll have to replace all instances of stateId.

Code:
<Custom Apply Effect>
// Increase the stockpile stack by 1
user.addStateCounter(stateId, 1);
// Cap the stockpile stack at 3
user.clampStateCounter(stateId, 1, 3);

</Custom Apply Effect>

<Custom Respond Effect>
user.addStateCounter(stateId, -1);

if (user.getStateCounter(stateId) == 0)
    user.removeState(stateId);
</Custom Respond Effect>

I didn't see anything actually wrong with your code beyond the "==" already mentioned. This does cut the number of lines of code in about half, so if it still doesn't work it should be a bit easier to troubleshoot.

Some recommendations:
- Turn on the plugin parameter that shows you the state counters so you can see what's happening
- Make sure you're starting a new play test, not loading a save or using the Battle Test from the editor
- If it still doesn't work, you should start a new thread for help troubleshooting
 
Last edited:

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
29
Reaction score
5
First Language
english
Primarily Uses
thank you for your help in refining the code i found from play testing
Okay...it makes the most sense to post the current actual code you're using. Otherwise, how are we to know there isn't some other little change that's causing your problems?

I'm going to get rid of the extra variable stuff and just use the state counter commands to make this easier to follow. As before, you'll have to replace all instances of stateId.

Code:
<Custom Apply Effect>
// Increase the stockpile stack by 1
user.addStateCounter(stateId, 1);
// Cap the stockpile stack at 3
user.clampStateCounter(stateId, 1, 3);

</Custom Apply Effect>

<Custom Respond Effect>
user.addStateCounter(stateId, -1);

if (user.getStateCounter(stateId) == 0){
    user.removeState(stateId);
    user.clearStateCounter(stateId);
}
</Custom Respond Effect>

I didn't see anything actually wrong with your code beyond the "==" already mentioned. This does cut the number of lines of code in about half, so if it still doesn't work it should be a bit easier to troubleshoot.

Some recommendations:
- Turn on the plugin parameter that shows you the state counters so you can see what's happening
- Make sure you're starting a new play test, not loading a save or using the Battle Test from the editor
- If it still doesn't work, you should start a new thread for help troubleshooting

with both sides having the state that is was using user.---- instead of target.-- which was the issue
thank you for your help
 

DrBuni

Regular
Regular
Joined
Dec 27, 2020
Messages
234
Reaction score
143
First Language
.
Primarily Uses
RMMV
Why are you using this second user._stockpile variable? If you're also using state counters, everything you're doing with the stockpile variable can just be done with the counters directly...I don't see the point of messing with two different things.

Aside from that, your error is this line:

if (user._stockpile = 0){
That line is setting the stockpile variable equal to 0. If you're trying to check whether it is equal to 0, that's two equal signs: if (user._stockpile==0)


No. For one, 1 and 0.1 are completely different numbers (I know that's obvious, and I don't intend it to come across as snarky, but you typed them both as ideas :stickytongue:).

For another, that's not how buffs work in RPG Maker. They aren't additive, they're multiplicative - the buff formula is multiplied by your base parameter value.

So if you have two layers of ATK buff on, and your ATK is 25, this._buffs[paramId] is going to be 2, and the formula's result of 1.5 is what your ATK is multiplied by.

In order to do what you want, you could not use buffs. Use states with a plugin such as Quasi Param Plus that allows you to attach flat values to states (and Yanfly's Buffs and States already allows you to stack states like buffs if you want).

Or...


You simply make it add the buffRate instead of multiply it.


No, not quite right. You don't want to mess with the paramRate, that's nothing to do with elemental anything, we're talking about parameters. If you go into an Actor, Class or State, one of the traits you can select is Parameter and it's a multiplier.

Just change the part of the formula that you actually want to change - the buffs.
Code:
(base + plus) * paramRate + buffRate + flat

Then you'd do what you proposed above, making the Buff formula be this._buffs[paramId] and it will add 1 point for each stack of buff.
The states as buffs idea sounds cleaner than messing too much with stuff I don't understand well. I will give it a try, thanks!
 

poppicha

Villager
Member
Joined
Aug 30, 2015
Messages
28
Reaction score
18
First Language
Thai
Primarily Uses
RMMV
Hello, I'd like to sort actors' skills in Window_SkillList/BattleSkill by MP cost. Can someone help me? I tried something like SceneManager._scene._skillWindow.sort(function(a, b) ... but I still can't get it right.
 

Latest Threads

Latest Profile Posts

I just saw someone's post that had an instagram link. I have yet to be able to open that site up once, ever, or have an embed of it work (it just straight up won't show either of them). And I haven't really found a reason to try to fix the problem, either XD
I want to go play piano now. This is gonna be my stopping point today (yes, I’m very slow at drafting). Might have a few too many curly Qs? Obviously gotta finish the limbs and clean up. There are a few more outfit details I need to add. Probably going to do a background so that the pose makes sense, LOL.

IMG_0515.jpeg
Do you believe me now?

BTW not my insta, not my post. Different John.
It's been long time since last I'm tinkering with RPG Maker ~

Forum statistics

Threads
135,049
Messages
1,253,310
Members
178,024
Latest member
itaire
Top