JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 15 of 171 View original ↗
  1. Liquidize said:
    Using your example in the above post, you could do something like this in a script call event (with the page settings as Battle and Turn 0):

    (function(){$gameTroop.members().forEach(function(member){member.enemy().params[2] = ($gameVariables.value(67) + $gameVariables.value(32))/$gameVariables.value(43);});})();It would set all enemies attack to the formula you provided when the battle starts, but again a plugin would be better, as this script call would need to be in every troop event. 
    Wow that looks a lot more complicated that I was thinking it would be.

    Would you be able to use this method to adjust the amount of gold and exp that enemy drops or would that be completely different?
  2. So something like x=0;if (item.elementId=2){x×2}else {x}

    Where x is damage dealt by a skill should work
  3. ragnorak6608 said:
    Wow that looks a lot more complicated that I was thinking it would be.

    Would you be able to use this method to adjust the amount of gold and exp that enemy drops or would that be completely different?
    Technically yes, one small thing to note though is that method changes the value of the database directly for the enemies, not on an individual instance. So all instances of the enemies effected will have that value, until you change the value by calling it again. Hence why a plugin would be better to change it on a per instance basis.

    To change the exp you can do the same thing, but instead of "member.enemy().params[2] = .." do "member.enemy().exp = value;" 

    forteller said:
    So something like x=0;if (item.elementId=2){x×2}else {x}

    Where x is damage dealt by a skill should work
    This would not work in the default formula field due to how the formula calculation is executed and performed. You would need a plugin that extends how damage calculation is done to allow for conditional statements.
  4. one more thing when assigning a value to a variable do you need to do anything different if the number is a decimal

    example:

    Code:
    $gameVariables.setValue(121,.01);
  5. I've been trying to learn Javascript for a while (both by reading through the stuff in the js window and by asking a friend of mine for help), though I'm still very much a beginner, so I apologize if this is a stupid question.

    I'm in the process of writing a chapter selection plugin, though I've hit a roadblock. At the moment, I'm able to display the chapters as choices, but selecting them doesn't do anything. How would I go about telling the system to check the position of the cursor so that every chapter option doesn't lead to the same place?

    Also, while on the subject of where each chapter leads, I'm also trying to set up the parameters for the plugin that'll determine the map the player is sent to by selecting the chapter it corresponds to. How would I go about doing that?

    I appreciate any and all help, and thank you for your time.
  6. How to properly check if an actor has a state? The plugin script call from the forum's document is wrong.
  7. Milena said:
    How to properly check if an actor has a state? The plugin script call from the forum's document is wrong.
    var actor = $gameParty.member()[0];var hasState =actor.isStateAffected(stateid);you can use any actor object, my example just uses the first party member.
  8. Alright, sirs, I got one question. I was able to find where in code I have the Grahics.frame_count. (Grahics.frameCount, duh.)

    But how can I get the equivalent to the good and old Graphics.frame_rate? I tried to search in rpg_core.js, but it redirects to the file fpsmeter.js, and sincerely, this file is a hell of mess.
  9. You could extend the Graphics class to have a "getFps" method that retrieves the fps value from fps meter. As the meter has a property that stores the current frame rate called "fps". Like so:

    Graphics.getFps = function() {if (this._fpsMeter) {return this._fpsMeter.fps;}return 0;};Just call "Graphics.getFps()" to get the value.
  10. If you really have to add new functions to existing classes, please prefix them with your name or something similar unique, to ensure compatiblity with other plugins. If possible, keep functions inside your namespace or anonymous function, depending on if they need to be public or not.
  11. Iavra said:
    If you really have to add new functions to existing classes, please prefix them with your name or something similar unique, to ensure compatiblity with other plugins. If possible, keep functions inside your namespace or anonymous function, depending on if they need to be public or not.
    This. I know I didn't in my example, but mine was merely an example to show how it could be done :) . I agree that you should always keep functions within a plugins namespace or anonymous function.
  12. Thank you, guys. Any advice on how doing this (namespace, anonymous function), I would be grateful.

    (I never searched about this before, because it's not urgent for me. I'm starting right now with this Javascript programming it's not much of a urgent concern for me. If it at least works, it's already something good for now.)

    Okay, so... I called it frameRate (well, it`s more obvious and therefore better), and the alternative path returning 60 instead, as I will need for some operations and we can't divide by zero.

    And, I'm aliasing in my scripts this way:

    var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;I guess I will need to do like in RGSS and create a "original alias" putting the prefix, etc. :p

    If everything's fine, then my first Javascript is almost ready.

    Thanks again!
  13. In this post here, i've posted the general structure of my plugins: http://forums.rpgmakerweb.com/index.php?/topic/53605-question-about-js-parameters-and-plugin-command/page-2#entry532417


    If you write your plugins inside an anonymous function, the names of your variables don't matter, because they are scoped to that function only and don't mess up with others. If you want to make them public (so that other scripters can provide compatibility patches, for example), you should add them to the plugin module (in the example, that would be MODULE.PLUGIN).
  14. Oh yeah, it's already wrapped inside a anonymous function, if is this you want to know. (There was something similar in Ruby if I recall corectly...)

    I pretty much already started my script this way, but I haven't realized that it should be because of this. I found this strange at first, I never had the need to use anything like this in RGSS...

    I didn't know about using Modules like this too, so thanks for all these info. Now I will just need to understand Namespaces here (I saw Namespaces in Visual Studio before, should be the same concept)
  15. Well, JavaScript actually doesn't know about the concept of "namespaces" or "modules", but we are using objects to emulate them. This:

    var MODULE = {};creates an object, that can be used to "namespace" and store other objects and functions inside of it. Everything you declare with "var" is scoped to the surrounding function, which is why we are using an anonymous function to prevent variables from leaking to the outside and use an object, that was declared outside the function, to make our API public. If you want to do everything in the function, you could just assign the object to the window, like this:
    Code:
    window.MODULE = {};
    Another upside of using anonymous functions is, that we can "use strict"; in them. Strict mode always applies to a whole function and since the base scripts don't use strict mode, we can't do so, either, unless we create a new function. Strict mode does a couple of things, including:- Preventing us from accidently creating public variables (like "myVar = 1;" instead of "var myVar = 1;").

    - Preventing "eval" from modifying variables outside of it.

    - Disabling access to arguments.caller/callee, which are slow and not very OO.

    Also, you should remember, that a for-loop doesn't create its own scope, so in this example:

    Code:
    for(var i = 0, max = 5; i < max; ++i) {    // stuff}alert(i);
    The alert will actually show 5. This means, that if you are using loops at the root of your plugin, without wrapping it in an anonymous function, you will leak the loop-variable to the public scope.
  16. Hmm, gotcha, that's important to know.

    However my current plugin that I'm developing right now is half user-utility and half scripter-utility (it's kind of a expansion of one of the Game classes)

    How should I proceed? Should l put the functions that can be used externally (some are the new ones) outside a anonymous function (so we can reach them, for example, with the Conditional Branch command event or other scripts), and all the alias inside?

    Soon my script will be " ready"  and I will show you what I mean.
  17. Oh Yeah, sorry for double posting, but I put everything in the anonymous function and it's working fine for what I want.( Call as a Conditional Branch in a event command)

    But that's not the problem. I forgot to report this, but the function

    Graphics.getFps();whatever the name I put on it isn't working by any means. It's saying in Console just "undefined" when not showing the code, once I try to call it by a simple script in a event with

    console.log(Graphics.getFps());It didn't worked either inside nor outside the anonymous function, as separated from Graphics or not, with protoype or not, with FPS turned on and off, and another couple of different ways. I'm thinking that the _fpsMeter does not have the "fps" function (neither fps() or whatever similar).

    Just to report this, I'm working in a solution right now (let's go mess with that mess of file called fpsmeter.js)
  18. How do I get the damage of a hit as a value with Javascript?

    I want to use it with Yanfly's buff and states core, and make poison damage based on the user's attack, but I have no idea how to get the damage.

    I am fully aware that there is a plugin that does specifically that, but it seems to have compatibility issues with Yanfly's buff and states core.
  19. So I wrote a plugin that enables saving/loading to/from a specified save and everything works fine as far as I can tell but for some reason this error is displayed :
    Edit: wrong picture ^^


    I don't think it's due to my plugin, as far as I can tell it's something to do with the game trying to start an event that's not there but it only shows when loading and not everytime the loading of that map or even that event is done (the event has multiple pages and the game is saved once per page or so and when the page is past 4 it doesnt work anymore)
    I hope someone sees something I don't ^^

    ps: Also some of the events have been done on mac and others on windows could this pose a problem?