JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 58 of 171 View original ↗
  1. That's either because if statements don't return values or because you're putting a semicolon between the if and the else block (or both). Can you try using something like:
    Code:
    $gameParty.battleMembers()[0].actorId() == 1 ? 99 : 5
    using the ternary operator?
  2. Can you show how it actually looks in the troop event command window?

    And have you tried breaking it into multiple lines instead of a single line and see if that works?
  3. Thanks! Seems like the semicolon was the culprit. It's working now. Glad to get the figured out. I thought the battleMember thing just wasn't going to work, but now it seems to work normally.
  4. If anyone could be so kind...

    Why isn't this working?

    Code:
    if (!$gameParty.Members()[0].isStateAffected(1)) {1} else {0}

    It's supposed to be the script setting a variable in an event. As you can see, if the party member is alive, it should set the variable to 1, otherwise to 0. But it's just returning 0 regardless. It's driving me crazy, because I usually know what I don't know, and this one I really think I do know, and it sure looks like it should just work. I've used that sort of syntax before, and I can't find anything wrong with it. There must be something in context I don't know.
  5. If you're using Control Variables and setting it to a script call, you can try using:
    Code:
    $gameParty.members()[0].isStateAffected(1) ? 1 : 0
    because:
    1. I personally wouldn't rely on if statements returning values even though in your case it does.
    2. Members() should be members() (JavaScript is case-sensitive)
  6. Thanks, it was the capitalization. I actually know how that's supposed to work, but my brain is weird. I had copy, pasted, and altered it, and during that process "checked" that it was capitalized properly, which meant my internal "$capitalization.isCorrect()" value had already returned "true" and that line of processing was skipped thereafter.
  7. I am asking this too late and I am not sure if this is the correct board, but the other javascript related boards seem not be the correct ones for me either.

    Is it worth trying to publish a plugin for a functionality that has already been done, maybe also multiple times, but different?
    With different I mean the existing plugin(s) may have functionality the one I have in mind lacks, but mine would have functionality the other one(s) seem(s) not to provide.

    For a particular example: There seem to be many plugins either in the 'request' or 'released' boards that are related to item and skill sorting.
    I found at least 3:
    - One that uses database notetags to change the sort order
    - One that sorts the skills and/or items just alphabetically
    - One that let's the player swap items in the sort order
    and I am pretty sure there are many more.

    My already released plugin has multiple sort orders included, but they just don't belong into it as the plugin is related to Scene_Battle (Now it is 2 or 3 plugins in one) .

    I really want to split my plugin and release another one, but I don't know if it is worth the time?
  8. @BurningOrca I say split it if you feel it will better serve your purpose and/or the community. More options is not a bad thing.
  9. I am using different yanfly plugins, but I am not sure if I need them.

    My idea is, that if a player uses a special skill, and the attack will be a critical hit, different things can happen:

    1 the target will get a state
    2 the user will get a state
    3 users party will get a state
    4 user gets healed by x% of max hp
    5 users party gets healed by x% of users max hp.

    Is this possible to do?
    If yes how to write the different if clauses?

    And the last thing is, I am using yanflys skill mastery, so I want the skills to do these effects from a certain lvl on. This code I found on yanflys page. But I am not sure if I can combine it if an other if clause. Is this possible?

    Best regards
    Nebu
  10. Hi,

    Any equivalent to this in RPG Maker MV? In VXa I would have done:

    if SceneManager.scene_is?(Scene_Map)
    #do this
    end

    So only execute this code if you're in Scene_Map.
  11. I believe this could work for that:
    Code:
    if (SceneManager._scene instanceof Scene_Map) {
        // do this
    }
  12. Excellent, thank you.
  13. Is there a conditional branch script command or something to determine if an event ID has been removed using the erase event command? I am using a parallel event to execute a specific event's move route based on whether the player is moving or not, and I want to be able to have that parallel event stop processing when the event it's controlling has been deleted.
  14. I think you can use a script call to:
    Code:
    $gameMap.event(event_id_goes_here)._erased
    in a conditional branch's conditions to check if an event with the specified ID has been erased via he Erase Event command.
  15. That worked, thanks!
  16. What is the method to change player's location / transfer him within same map? Looking for this one

    Code:
    $gamePlayer.moveTo(x, y);

    EDIT:
    Found it :) It is
    Code:
    $gamePlayer.locate(x, y);
  17. Hello all, My question is on the Yanfly Attachable Augment plugin, is it possible that specific weapon and armor are found with Augments already on them? It's doesn't have to be random or anything just pre-determined Augment.
  18. When I look at plugins from other creators I can see two different styles.
    Many seem to wrap a self calling function around their code.
    Other, e.g. Yanfly does not do this and I just adopted this style of coding.

    So I am just curious:
    - What are the real reasons for wrapping your code with a self calling function?
    - What are the real reasons for not doing this?
  19. Mostly a matter of preference.

    The real reason for wrapping the code in an Immediately Invoked Function Expression (IIFE) is to encapsulate variables that aren't intended to be public. It's a way to avoid creating global variables.

    Code:
    const publicVariable = {};
    ;(function () {
       const privateVariable = 5;
       publicVariable.value = privateVariable ** 2;
    })();

    Now other plugins can access the public variable but not the private variable. A common purpose is when you create alias for functions, there's generally no need to expose the alias itself to the public.

    Alternatively, you can create a namespace for yourself and then run everything off the namespace.

    Code:
    const MyNamespace = {};
    MyNamespace._privateVariable = 5;
    MyNamespace.publicVariable = MyNamespace._privateVariable ** 2;

    Javascript doesn't have private variables (not yet...), but the underscore is used by convention to indicate that it's supposed to be private.

    You can also use a namespace within an IIFE to both encapsulate variables and save some keystrokes.

    Code:
    const MyNamespace = {};
    ;(function ($) {
       const privateVariable = 5;
       $.value = privateVariable ** 2;
    })(MyNamespace);

    Nowadays, all of this is considered "old school" ways of handling variable scope. Web development these days use modules with import/export statements to manage this, however, I don't think the module implementation will be supported by the MV engine or adopted by plugin writers any time soon.
  20. @Aloe Guvner Thank you for the detailed answer.
    I propably already accessed a lot of underscore variables without knowing that I shouldn't and declared a lot of underscore variables without knowing the underscores purpose, but now thanks to you I know it which is good for future coding.