JavaScript questions that don't deserve their own thread

Discussion in 'Javascript/Plugin Support' started by Shaz, Oct 23, 2015.

  1. Sleepy Kitten Games

    Sleepy Kitten Games Veteran Veteran

    Messages:
    421
    Likes Received:
    183
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm using the most recent version of MV.
    Which means I probably did something wrong when trying to correct the script bits. Not out of character for me.
     
  2. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @GameFire
    Um ok well did you try what I sent in the last post?

    Edit:
    To be clear:
    1. You are sure that it is a valid string
    2. You are receiving an error message that "string.includes" is not a function

    This would only happen if your version of MV is not the most recent (1.6+), yet you claim that you have the most recent version. Are you sure?
     
    Last edited: Oct 19, 2018
  3. Sleepy Kitten Games

    Sleepy Kitten Games Veteran Veteran

    Messages:
    421
    Likes Received:
    183
    First Language:
    English
    Primarily Uses:
    RMMV
    The latest attempts at getting this working:
    ◆If:Script:$gameVariables.value(101).includes(' ')
    ◆Script:var index = $gameVariables.value(101).indexOf(' ');
    : :var slice = $gameVariables.value(101).slice(index);
    : :$gameVariables.setValue(102, slice);
    ◆If:Script:$gameVariables.value(102).includes(' ')
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Is \v[102] really your surname?
    ◆Show Choices:Yes, No (Window, Right, #1, #2)
    :When Yes
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Alright, then.
    ◆Script:$gameActors.actor(10).setName($gameVariables.value(101))

    :When No
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Then what is your surname?
    ◆Label:Surname
    ◆Plugin Command:InputDialog text Enter your surname.
    ◆Plugin Command:InputDialog maxLength 16
    ◆Plugin Command:InputDialog variableID 102
    ◆Plugin Command:InputDialog open
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Is \v[102] your surname, then?
    ◆Show Choices:Yes, No (Window, Right, #1, #2)
    :When Yes
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Alright, then.
    ◆Script:$gameActors.actor(10).setName($gameVariables.value(101))

    :When No
    ◆Jump to Label:Surname

    :End

    :End

    :End

    :Else
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Is \v[101] your name?
    ◆Show Choices:Yes, No (Window, Right, #1, #2)
    :When Yes
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Alright, then.
    ◆Script:$gameActors.actor(10).setName($gameVariables.value(101))
    ◆Common Event:Wrong Name

    :When No
    ◆Text:None, Window, Bottom
    : :\nt<\c[1]Shadowy Figure>Then what\fi is\fr your name?
    ◆Jump to Label:Name

    :End

    :End
    That's partially working, now. But when I set the character's name to "Fir Mid Las", it now has " Mid Las" as variable 102.
    So then I tried tweaking that first script block to look like this:
    ◆Script:var index = $gameVariables.value(101).indexOf(' ');
    : :var slice = ($gameVariables.value(101).slice(index)) + 1;
    : :$gameVariables.setValue(101, $gameVariables.value(101).slice(-(index + 1)));
    : :$gameVariables.setValue(102, slice);
    That makes it so 101 is set to " Las", while 102 is set to " Mid Las1".
    I tried just removing the +1's, all that did was make it so 102 wasn't set to " Mid Las1", just " Mid Las". Although now 101 is set to Mid, so I suppose that's some progress?
    Edit: No more of the "string.includes" is not a function. Yes, I am sure it's a valid string, and yes, I'm sure I'm on the latest version of MV. 1.6.1, yeah?
     
  4. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Ok, got it. If the error (...).includes is not a function comes up again, it's because it's being called on something that's not a string.

    Code:
    var slice = ($gameVariables.value(101).slice(index)) + 1;
    To explain what this is doing, and why you didn't see results as you expected. The +1 is on the outside, so it's essentially the same as:
    Code:
    " Mid Las" + 1
    The "+" operator is both for numerical addition and string concatenation. Because the first argument is a string, it chooses to do concatenation and treats the "1" as a string.

    Then you have this line:
    Code:
    $gameVariables.setValue(101, $gameVariables.value(101).slice(-(index + 1)));
    Just so you're aware, since you have a negative sign in the slice argument, when you slice to a negative integer it slices from the back instead of from the front.

    And what is your question? You want to only have "Las" in that variable? You can just slice it again.
    Remember that you can experiment in the console too (press F8 during playtest), which is a lot faster than constantly updating an event and restarting a playtest.
     
  5. Sleepy Kitten Games

    Sleepy Kitten Games Veteran Veteran

    Messages:
    421
    Likes Received:
    183
    First Language:
    English
    Primarily Uses:
    RMMV
    Yes, I realized the reasoning for it adding the 1 to the end of the 102 string. What I was trying to fix was how it has a space sitting at the front. " Mid Las" versus "Mid Las".
     
  6. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    If you have "Fir Mid Las" and you're currently slicing it to " Mid Las" but you want to slice it to "Mid Las", then just slice it one character later. Don't include the extra space in your slice.
    "Fir Mid Las".slice(3) --> " Mid Las"
    "Fir Mid Las".slice(4) --> "Mid Las"
     
  7. Sleepy Kitten Games

    Sleepy Kitten Games Veteran Veteran

    Messages:
    421
    Likes Received:
    183
    First Language:
    English
    Primarily Uses:
    RMMV
    Except that's the problem. The space won't be at the same place each time. One person could set it to "Name Name Name". Another could set it to "Fir Mid Las". Et cetera. Hence using "index" as a variable instead of a set number.
     
  8. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    If you need it to start 1 past the index, add 1 to index
     
  9. Sleepy Kitten Games

    Sleepy Kitten Games Veteran Veteran

    Messages:
    421
    Likes Received:
    183
    First Language:
    English
    Primarily Uses:
    RMMV
    I tried doing that. But that made it so that 102 was set to " Mid Las1".
     
  10. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    No you added 1 to the string, not to the index, as I explained a few posts ago.

    Was trying to walk you through it, but I think we've monopolized this thread enough so here's the code you need to set your variable 102:
    Code:
    var index = $gameVariables.value(101).indexOf(' ');
    var slice = $gameVariables.value(101).slice(index + 1); // start after the space
    $gameVariables.setValue(102, slice);
    
    I think you may want to start a thread if you need more questions, since it's getting to be kind of a mini-thread here.
     
  11. punchybot

    punchybot Veteran Veteran

    Messages:
    99
    Likes Received:
    215
    First Language:
    English
    Primarily Uses:
    RMMV
    I am using OctoPack Battler Plugin, and I have a question I can't seem to find the answer for.

    I added a new weapon type (Whip) to my game. My only issue is that when I attack an enemy with a whip weapon, it doesn't display with the "Weak!" pop up or reduce their shield. (For example an enemy is weak to fire, ice, sword, and whip. When the enemy is hit with fire, it reveals the weakness, and shield break status is reduced by 1. It will also display as a word popup that it was a weakness. It does this for the following two. For Whip, it is causing bonus damage, but it is not indicating it is a weakness, it is not reducing the shield value, and is not revealing as a weakness to the player.)

    I made sure to go into the plugin and add the required icons so it displays during fights. I made sure the weapon itself attacks with whip element.

    I hope I made it clear what my issue is. If someone can point me in the right direction where I should be looking, that would be great!
     
  12. dicepool14

    dicepool14 Villager Member

    Messages:
    22
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm using this extension: http://yanfly.moe/2016/04/10/yep-91-equip-skill-tiers-rpg-maker-mv/
    For this plugin http://yanfly.moe/2016/04/08/yep-90-equip-battle-skills-rpg-maker-mv/

    The plugin gives each actor a certain number of 'slots' to equip their known skills in. So you can only bring, say, 5 skills into a battle.

    The extension lets you separate the slots into tiers and provides a maximum number of each tier that can be equipped. So, for example, 2 Offensive, 2 Defensive, and 1 Passive.

    The plugin has a plugin command for increasing the number of slots a given actor has. So you can defeat a boss, for example, and gain +1 skill slots. The extension does not have a plugin command for increasing the number of 'tier slots'. So, if you level up to, say, 10 skill slots, you're still bound by 2 Offensive, 2 Defensive, and 1 Passive, forever.

    I don't know how to fix this. My first thought was to find the variable inside the extension that controls the max number of tier slots, so that maybe a script call of some kind could increase them? I went looking and put together something like: $gameActors.actor(1).equipTierSlot = {1: +1}; but, while it doesn't crash the game (like all the other things I tried), it doesn't do anything either.

    Any ideas?
     
  13. ReyBen47

    ReyBen47 Villager Member

    Messages:
    10
    Likes Received:
    0
    First Language:
    english
    Primarily Uses:
    RMVXA
    for yanfly's class change plugin is there a way i can hide a class from the menu?
     
  14. Kyuukon

    Kyuukon 主人公 Veteran

    Messages:
    2,216
    Likes Received:
    1,073
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    What does this line really do and how it affects the sprites ingame?
    I decided to comment it out since it makes it difficult for me to target a specific enemy sprite. But I wonder if that will break something else?
     
  15. Intezil

    Intezil Villager Member

    Messages:
    12
    Likes Received:
    2
    Quick question;

    I'm trying to make it so that when you equip something that raises your max hp or mp, your current hp or mp increases or decreases the same way (so if your armor adds +2 MHP, you gain +2 HP. If you remove it, you lose 2 HP). Unfortunately, I know virtually nothing about JS. I think I've found the right bit of code in rpg_objects.js;

    Game_BattlerBase.prototype.addParam = function(paramId, value) {
    this._paramPlus[paramId] += value;
    this.refresh();

    which I'm trying to edit, by cutting and pasting from other parts of the script. This is what I have right now

    Game_BattlerBase.prototype.addParam = function(paramId, value) {
    this._paramPlus[paramId] += value;
    if (paramId === 0) {
    this.gainHp(value); // MHP
    } else if (paramId === 1) {
    this.gainMp(value); // MMP
    }
    this.refresh();
    };

    But it doesn't appear to work. Any help would be appreciated.
     
  16. woootbm

    woootbm Super Sand Legend Veteran

    Messages:
    164
    Likes Received:
    84
    Location:
    'Murica
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm using Yanfly's Main Menu Manager plugin. I'm trying to add new things via common events, and functionality-wise I'm getting all the stuff I need out of it.

    My question is, though, how do I open a window on top of the Main Menu?

    Right now I'm using a Common Event to "Show Choices" and then finding ways to open things from there (as an example, I'm consolidating Save, Options, and Exit to an item called "System"). But doing so closes the whole Main Menu and opens the tiny little choice window by itself. I don't really like the flow of that.

    Edit: to offer some specific examples, the command I use in the plugin is "this.callCommonEvent.bind(this)". And the common event I use involves the "Show Choices" command.
     
    Last edited: Nov 29, 2018
  17. Zanto1050

    Zanto1050 Villager Member

    Messages:
    14
    Likes Received:
    11
    First Language:
    English
    Primarily Uses:
    RMMV
    I have a simple question and I hope I'm posting in an appropriate place. I'm wanting to make a state that will counter an attack with something like contact damage. I found some code from Yanfly that can do that, http://yanfly.moe/2016/03/12/tips-tricks-thornmail/. Problem is I want to add an element to the recoil damage. Such as, the state would be an earth shield so when the enemy attacks they will get recoil damage and take extra damage if they're weak to earth.

    Where and what should I add into the formula to give the recoil an element?
     
  18. dicepool14

    dicepool14 Villager Member

    Messages:
    22
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    So, I'm trying to make Luck do nothing.

    I got Yanfly's Base Parameter Control plugin. http://yanfly.moe/2016/03/25/yep-86-base-parameter-control/

    The base formula given for "Luck Effect" is "Math.max(1.0 + (user.luk - target.luk) * 0.001, 0.0)". At first glance, I think this means that for each point of Luck you have over your opponent, your chance of giving them a State is increased by 0.1%? Or something?

    It doesn't really matter. I want Luck to have no affect on states, but also not mess up anything else.

    Should I change it to "Math.max(1.0 + (user.luk - target.luk) * 0.000, 0.0)",
    or "Math.max(1.0 + (0 - 0) * 0.000, 0.0)",
    or "Math.max(1.0)" ?
    Does it matter???
     
  19. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,455
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Yup, that's how I interpret it too.

    You can literally just change it to "1" (without the quotes), just the number 1. So then the % chance of inflicting a state is multiplied by 1 which does nothing.
     
  20. dicepool14

    dicepool14 Villager Member

    Messages:
    22
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Awesome! Thank you. I'll stop sweating about that.

    So, now, to complete my dastardly plan, I've used Yanfly's Critical Control plugin to change the Critical Rate formula from:
    rate = user.cri * (1 - target.cev);
    to
    rate = ((user.cri) + (user.luk * 0.002)) * (1 - target.cev);

    Which I believe will now cause every 5 points of Luck to increase Crit Rate by 1%! So that, for example, a character with 10 Luck and a class with a native +2% Crit Rate will have: ((0.02) + (10 * 0.002)) * (1 - target.cev); = 4% base chance to crit!

    That math checks out, too, right? It's not going to like... make everything explode?
     

Share This Page