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.
JavaScript questions that don't deserve their own thread
● ARCHIVED · READ-ONLY
-
-
@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. -
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. -
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' -
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 eitherHello.
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.trueorfalseat 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. -
Huh, I didn't know that. In every other language I regularily work with they are considered complex, as they are an array of the actually primitive character "under the hood".In JavaScript, strings are also considered primitives.
-
If the Math.floor() function always rounds down, what rounds up?
Thanks. -
Math.ceil()If the Math.floor() function always rounds down, what rounds up?
Thanks. -
@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. -
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?
thank you<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> -
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? -
Why are you using this secondhi 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?
user._stockpilevariable? 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:).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?
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.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?
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.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?
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 bethis._buffs[paramId]and it will add 1 point for each stack of buff. -
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 seconduser._stockpilevariable? 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) -
You are also repeatedly using the variable "stateId" but that should be a number - the ID of the state.thank you for the help but the counter is still not counting down when the user is hit by an attack.
-
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 skillYou are also repeatedly using the variable "stateId" but that should be a number - the ID of the state.
-
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 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
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 -
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 -
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!Why are you using this second
user._stockpilevariable? 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 bethis._buffs[paramId]and it will add 1 point for each stack of buff. -
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.
-
That sort() syntax you're referencing is a JavaScript method for arrays. The skillWindow isn't an array, it's its own Object of type Window_SkillList.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.
You can try applying that to the portion of the window's data that is an array. Try modifying the makeItemList() method from rpg_windows.js:
Code:Window_SkillList.prototype.makeItemList = function() { if (this._actor) { this._data = this._actor.skills().filter(function(item) { return this.includes(item); }, this); this._data.sort((a, b) => $dataSkills[a].mpCost-$dataSkills[b].mpCost); } else { this._data = []; } };
See how that works.