JavaScript questions that don't deserve their own thread

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

  1. Sword of Spirit

    Sword of Spirit Veteran Veteran

    Messages:
    114
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    I can't seem to get either of those to work. I'm checking to see if Actor 1 is in position 0:

    Code:
    if ($gameParty.battleMembers()[0].actorId() == 1) {99}; else {5};
    
    if ($gameActors.actor(1) == $gameParty.battleMembers()[0]) {99}; else {5};
    That's what I'm trying to use, but to no effect. This is putting a number into a variable via a troop event, and I haven't had any problems using expressions like "$gameParty.battleMembers()[0].def-10" in those events once I figured them out. But this one has me stumped.

    Alternatively, I could work with finding out whether a battle member has a state. That might even be a better method, but I'm having a hard time getting that to work either. Darn battleMembers.
     
  2. KockaAdmiralac

    KockaAdmiralac Cube-shaped garbage can Veteran

    Messages:
    570
    Likes Received:
    156
    Location:
    Belgrade
    First Language:
    Serbian
    Primarily Uses:
    N/A
    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?
     
    Sword of Spirit likes this.
  3. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,476
    Likes Received:
    2,869
    Location:
    Philippines
    First Language:
    Tagalog
    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?
     
    Sword of Spirit likes this.
  4. Sword of Spirit

    Sword of Spirit Veteran Veteran

    Messages:
    114
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    Engr. Adiktuzmiko likes this.
  5. Sword of Spirit

    Sword of Spirit Veteran Veteran

    Messages:
    114
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
  6. KockaAdmiralac

    KockaAdmiralac Cube-shaped garbage can Veteran

    Messages:
    570
    Likes Received:
    156
    Location:
    Belgrade
    First Language:
    Serbian
    Primarily Uses:
    N/A
    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)
     
  7. Sword of Spirit

    Sword of Spirit Veteran Veteran

    Messages:
    114
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
  8. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    77
    Likes Received:
    56
    First Language:
    German
    Primarily Uses:
    RMMV
    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?
     
  9. Johnboy

    Johnboy Veteran Veteran

    Messages:
    317
    Likes Received:
    104
    Location:
    Canadia
    First Language:
    English
    @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.
     
  10. Nebu

    Nebu Villager Member

    Messages:
    29
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    N/A
    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
     
  11. Amy Pond

    Amy Pond Veteran Veteran

    Messages:
    667
    Likes Received:
    1,359
    First Language:
    English (UK)
    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.
     
  12. KockaAdmiralac

    KockaAdmiralac Cube-shaped garbage can Veteran

    Messages:
    570
    Likes Received:
    156
    Location:
    Belgrade
    First Language:
    Serbian
    Primarily Uses:
    N/A
    I believe this could work for that:
    Code:
    if (SceneManager._scene instanceof Scene_Map) {
        // do this
    }
    
     
    Amy Pond likes this.
  13. Amy Pond

    Amy Pond Veteran Veteran

    Messages:
    667
    Likes Received:
    1,359
    First Language:
    English (UK)
    Excellent, thank you.
     
  14. Vassim74

    Vassim74 It's a Secret! Veteran

    Messages:
    103
    Likes Received:
    72
    Location:
    California
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
  15. KockaAdmiralac

    KockaAdmiralac Cube-shaped garbage can Veteran

    Messages:
    570
    Likes Received:
    156
    Location:
    Belgrade
    First Language:
    Serbian
    Primarily Uses:
    N/A
    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.
     
    Vassim74 likes this.
  16. Vassim74

    Vassim74 It's a Secret! Veteran

    Messages:
    103
    Likes Received:
    72
    Location:
    California
    First Language:
    English
    Primarily Uses:
    RMMV
    That worked, thanks!
     
  17. V_Aero

    V_Aero Veteran Veteran

    Messages:
    39
    Likes Received:
    21
    Location:
    Germany
    First Language:
    german
    Primarily Uses:
    RMMV
    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);
     
    Last edited: May 7, 2019
  18. Dicleon

    Dicleon Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    French
    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.
     
  19. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    77
    Likes Received:
    56
    First Language:
    German
    Primarily Uses:
    RMMV
    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?
     
  20. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,561
    Likes Received:
    978
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     

Share This Page