JavaScript questions that don't deserve their own thread

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

  1. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    102
    Likes Received:
    82
    First Language:
    German
    Primarily Uses:
    RMMV
    @Anarcho-paladin: Neither: As plugins are written in javascript I thought this is the right place to post this question.
    I just want to know if it makes sense to release another plugin for the same purpose of an already existing one. Some plugin authors do that, but I see no much sense in doing that. People might not even pick it up, as they have already a working plugin for the purpose. Maybe my opinion is completely wrong.
     
  2. Ossra

    Ossra Formerly Exhydra Veteran

    Messages:
    851
    Likes Received:
    617
    First Language:
    English
    Primarily Uses:
    RMMV
    @BurningOrca That is up to you, really. Perhaps the plugins go about the same end result in different ways. Perhaps one is more compatible with the plugins another user has in a project. You can never tell how useful a plugin will be to someone.
     
  3. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    As someone who used to make scripts on Ace even if Yanfly has a similar script, I made my scripts have a bit of different application method. Like for most of Yanfly's event execution scripts, it gives the capability to run a common event during some trigger, while mine would let the user define an actual RGSS3 code instead...

    Also as Ossra said, there can exist different ways of implementing the same behavior, so that also gives justification to the other plugin. If yours would work have the same output and same method of work, then yeah there's not much point except for the sake of you having your own (which is also fine).

    This also gives people options in case the plugin of one coder has problems in their project or when the creator of that plugin stops supporting and/or in extreme cases, makes their plugins unavailable for use.

    It might be a bit small in amount but I see threads or posts every now and then which asks for alternatives to the more known plugins due to incompatibilities and personal reasons.

    iirc the purpose of this thread is for questions about JS codes that doesnt directly relate to a plugin, or the creation of such.
     
    Aloe Guvner likes this.
  4. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,626
    Likes Received:
    1,047
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    There's also the concept of "feature bloat". Perhaps the existing plugin has that feature plus 49 other features. If yours only has the one feature it is more likely to be performant, easy to read, and compatible with other plugins.
     
    Engr. Adiktuzmiko likes this.
  5. BurningOrca

    BurningOrca Veteran Veteran

    Messages:
    102
    Likes Received:
    82
    First Language:
    German
    Primarily Uses:
    RMMV
    @Ossra @Engr. Adiktuzmiko @Aloe Guvner: Thank you all for your answers.
     
    Engr. Adiktuzmiko likes this.
  6. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    That's one of the reasons I have read from people not wanting to use a YEP for some features that they need.
     
  7. Critcap

    Critcap Instant Ramen Connoisseur Member

    Messages:
    4
    Likes Received:
    0
    Location:
    Development Hell
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey Guys,
    in Spriteset_Base.prototype.createBaseSprite it creates a new ScreenSprite called _blackScreen which is subsequently as a child to each _baseSprite in every Spriteset. Does _blackScreen serve no other purpose than being a black base for the _baseSprite and its save to assume it doesnt have anything to do with Screen fade ins and outs?
     
  8. staf00

    staf00 Veteran Veteran

    Messages:
    79
    Likes Received:
    9
    First Language:
    English
    Hi, I'm using most of Yanfly's plugins but the relevant ones to my question involve these 2 notetags. Basically I'm trying to create a spell that will cost however much mana the caster has left, whether they're at full mana, 1mp or somewhere in between. Then, damage dealt would correspond directly w/ how much mana was used to cast the spell. Right now, I got the 1st part working (MP Cost) but the damage dealt is always 0. I'm guessing it's cuz the game is looking at the unit's MP after it's been spent on the spell, not before. Any help is appreciated, thx.

    <Custom MP Cost>
    var mana = user.mp
    cost = user.mp
    </Custom MP Cost>
    <damage formula>
    value = a.mp
    </damage formula>
     
    Last edited: Oct 20, 2019
  9. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    As you suspected, yes, damage is calculated aftee paying the cost... You will need to set a variable equal to the MP before the cost is taken, and use that variable as the damage value.

    Like in the cost part do something like this first

    $gameVariables.set(ID,user.mp)

    then on your damage part, do

    value = $gameVariables.value(ID)

    Take note though that if that is your only damage formula, you can skip using the notetag and just type

    $gameVariables.value(ID)

    directly in the damage formula box of the skill. The damage formula box is already a JS evaluation box, no need to use a plugin for codes that fit and write nicely into the box.
     
    Starbird_Resources and staf00 like this.
  10. staf00

    staf00 Veteran Veteran

    Messages:
    79
    Likes Received:
    9
    First Language:
    English
    Thx, this seems like exactly what I needed! But when I try it, I'm still getting 0...This is what I have now in the skill's note box:


    <Custom Execution>
    $gameVariables.set(1,user.mp);
    </Custom Execution>
    <Custom MP Cost>
    cost = user.mp;
    </Custom MP Cost>

    Also, as per your suggestion, I put $gameVariables.value(ID) in the damage formula box. Actually i put $gameVariables.value(1)
    What am I doing wrong here? I've tried a couple of variations in the note box, such as putting $gameVariables.value(ID) in the <Custom MP Cost> tag and even making sure I had the semicolons (which I totally forgot to put the 1st time lol). Perhaps the value of the variable is changing in real-time as my unit's MP changes? Thus exhibiting the same problem I've been having from the beginning?
     
  11. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Variables set to things like HP and such usually dont change IRT because they get the value, not the pointer to the data. A lot of people actually put requests on the past to be able to do that with variables so they only need to "set" it once.

    But just in case, you can try to manually give it the value to ensure that it saves the value, not the pointer. I kinda forgot how to do that in JS though.

    Or first try actually using user.mp() on the variable setting instead of just user.mp. Because from my experience, when you set a variable to a JS function but only use the name without the () [which denotes a call to the function], it actually saves the whole function as text instead of evaluating it and saving the result.

    TBH though, using variable 1 is pretty risky, because its the first ever variable you might have been using it too on other stuff. It might not matter on the skill since the cost calculation happens right before execution too anyway, but it might cause problems with other stuff. Or it could also be affecting the skill.

    PS: Make sure to check it inside the cost part again instead of on the execute code.

    You can also add this, after the variable set and before the cost = code

    console.log($gameVariables.value(ID))

    And test your game while the console is ON, that way we can see what value is saved during the saving part.
     
    Last edited: Oct 20, 2019
    DarkSpectre and staf00 like this.
  12. DarkSpectre

    DarkSpectre Lover of all things game related... Member

    Messages:
    8
    Likes Received:
    10
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm having an issue with some script calls. I'm used to programming in Unity in C#, but decided to give some simple things a try in RPGMMV to start learning some basic java skills, but something in my script calls isn't functioning correctly.

    I keep getting errors revolving around undefined. Basically, what I'm trying to do is feed variables set in the database into the script call for adding/subtracting items.

    Code:
          ◆Script:var r = $gameVariables._data[8];
          :        :var q = $gameVariables._data[9];
          :        :$gameParty.gainItem($dataItems._data[r], -q);
    
          ◆Script:var r = $gameVariables._data[1];
          :        :var q = $gameVariables._data[2];
          :        :$gameParty.gainItem($dataItems[r], q);
          ◆Play SE:Bell2 (90, 100, 0)
    Any help would be appreciated, as I'm sure it's something simple I'm missing. Thank you!
     
  13. staf00

    staf00 Veteran Veteran

    Messages:
    79
    Likes Received:
    9
    First Language:
    English
    Still no luck in my attempts to create a spell that deals damage based on the amount of mana used to cast the spell (the spell uses all of the user's remaining mana, however much it might be). I looked through Yanfly's tips & tricks videos for guidance, especially when it comes to syntax and so forth. Here are a few I think might be useful, but try as I might...I just can't get the spell to work! If anyone can chime in and gimme a hand, I would forever be in your debt. (The stuff in bold might be useful for the spell I'm trying to create)

     
  14. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    @DarkSpectre please post the error message that you are getting so that we can have a better idea of what is happening.

    Also if that script code is how it looks exactly on your editor, Im pretty sure you have extra : lying in front of your lines... Delete those. I guess you copy pasted it from a screenshot of the event editor, and as such you also copied the : that was actually part of the event editor's UI instead of the code.
     
    DarkSpectre likes this.
  15. DarkSpectre

    DarkSpectre Lover of all things game related... Member

    Messages:
    8
    Likes Received:
    10
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    You are correct about me copying and pasting from the editor, my apologies, the extra : are from the interface as you suggested, and not part of the actual code.

    The exact error I’m receiving is:
    Cannot read property undefined of undefined.

    Thanks again for any help!
     
  16. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    @DarkSpectre

    I mean your actual code still has :, which it shouldnt have. Your script call shouldnt have any : in it.

    If you copy pasted from the editor to your post, your post should only have one : per line (from the UI, the leftmost : ), but your post have two : per line on the 2nd,3rd,5th,6th lines... Which means your actual code has : in it.

    So you should delete those extra : (the second ones) from the script call in your editor because they would indeed cause errors. A day ago, somebody made that same mistake and we ended up with 2 pages of post before we even realized that it was all because of that simple thing...

    As for the error, please test the game with console on, and see which code/line the error points to. Do this after you remove the extra : though.

    Also, calling ._data[id] isnt a good idea because if you do that, the auto-initialization being done by the .value(id) function wont kick in, so you might end up using variables that arent initialized with a value yet.

    I suggest using $gameVariables.value(id) instead of handling the ._data array directly.

    Your $dataItems call might also have a problem but Im not sure of the correct call for that right now.
     
    Last edited: Oct 24, 2019
    DarkSpectre likes this.
  17. DarkSpectre

    DarkSpectre Lover of all things game related... Member

    Messages:
    8
    Likes Received:
    10
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    @Engr. Adiktuzmiko

    Actually I just fixed this a moment ago, but your reply was partially correct. The issue wasn't anything to do with : in the code, it was just the way that the editor was displaying the script call in the common event I had it in. I believe they were being added by the editor because I was doing more than a single line of text in the script box. The actual syntax for the code I was using was like this:

    Code:
    var r = $gameVariables._data[8];
    var q = $gameVariables._data[9];
    $gameParty.gainItem($dataItems._data[r], -q);
    Because I copied the editor lines as text it copied the :
    upload_2019-10-23_22-1-57.png

    upload_2019-10-23_22-3-55.png

    upload_2019-10-23_22-5-41.png

    Anyways, what the actual problem was, was the way I was trying to access the variable as you mentioned above. I changed the previous codes to the below syntax, and now everything is A-OK. :LZScheeze:

    Code:
    $gameParty.gainItem($dataItems[$gameVariables.value(4)], -($gameVariables.value(5)));
    I just didn't know enough about Java Syntax yet to figure out what was going on. When I did some research on just regular JS, not specifically RPG Maker, I figured out what was going on, then found the correct way to access the variable data in the RPG Maker core codes.

    Thank you so much for all your help!
     
    Engr. Adiktuzmiko likes this.
  18. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Glad it all works now.. BTW, dont mix Java with JavaScript, they are different :)
     
    DarkSpectre likes this.
  19. DarkSpectre

    DarkSpectre Lover of all things game related... Member

    Messages:
    8
    Likes Received:
    10
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    Sorry, yea, I meant JS. I always used Unity or Unreal for my college stuff, so I'm just finally getting back into the RPG Maker stuff, and realized they went and changed languages on me while I was gone. Lol. I'll pick it up eventually, I just never had much use for JS before now.

    I managed to create a simple crafting system using events in the editor, and just couldn't seem to find a way to add an item by using a variable containing an ID and a variable containing a quantity without actually using the couple lines of script. (Not without running a conditional check for each and every item in the database anyways.)

    Now it works fully!

    It uses type Hidden Item A items set up as recipes, items setup as resources, and items you want to create. Then the user just adjusts variables for where the recipes start and end, and creates the recipe contents in the common event itself by copy-pasting the example and editing the values. I know it would have been much neater as a plugin, but I wanted to see if it was possible using mostly event commands for people like me who don't fully understand all of JS yet. Once I get a grasp on recursively accessing the arrays inside of structs utilizing JSON.parse, then maybe I'll give it a go at creating a plugin. I have found it surprisingly hard to find any video tutorials demonstrating how.

    Thanks again for all your help!
     
    Engr. Adiktuzmiko likes this.
  20. BloodletterQ

    BloodletterQ Chaotic Neutral Assassin Veteran

    Messages:
    1,460
    Likes Received:
    1,052
    Location:
    My head's in the clouds at least...
    First Language:
    English
    Primarily Uses:
    N/A
    For Alistair's Mana Barrier, is there a way to make a skill bypass the barrier?
     

Share This Page