JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 110 of 171 View original ↗
  1. Hii I'm sorry if this is a bad question but what's the difference between javascript classes and doing function.prototype stuff like rpg maker does it? I'm making a program (to help me make something in rpg maker, but it's not a plugin) and I'm starting to have a very long script with a bunch of those and I'm having an existential crisis thinking I should use classes and different script files. >_<
  2. Mushi said:
    Hii I'm sorry if this is a bad question but what's the difference between javascript classes and doing function.prototype stuff like rpg maker does it? I'm making a program (to help me make something in rpg maker, but it's not a plugin) and I'm starting to have a very long script with a bunch of those and I'm having an existential crisis thinking I should use classes and different script files. >_<
    The short answer is that RPG Maker's core scripts also use classes--they're just created using an older syntax. You're free to use the newer syntax if you want, but I personally prefer to try to keep my coding style consistent with that of the existing code that I'm extending/editing.
  3. I see okay if there's no difference I will keep doing what I'm doing, thank youu!!
  4. Is there a way to create a global variable whose name is based on an actor ID?

    I'm using Yanfly's Buffs and States core. I want to create a global variable that is equal to an actor's Attack when a state is applied.

    i.e.
    <Custom Apply Effect>
    var statAtk = a.atk
    </Custom Apply Effect>

    However, the issue is that in this form I believe that if you apply the state to another actor then 'statAtk' will be overwritten with the new target actor's Attack stat. So what I want is some way to have the statAtk variable created uniquely based on the targeted actor, but I don't know the syntax of how to do that in Javascript.
  5. Nate_Tillern said:
    Is there a way to create a global variable whose name is based on an actor ID?

    However, the issue is that in this form I believe that if you apply the state to another actor then 'statAtk' will be overwritten with the new target actor's Attack stat. So what I want is some way to have the statAtk variable created uniquely based on the targeted actor
    I'm confused about what you're trying to achieve. Where do you use this variable? How is it referenced?

    If you actually want a global variable, you should use a global variable:
    Code:
    $gameVariables.setValue(X, a.atk);
    replacing X with the variable's ID, and then you can reference it anyplace else.

    But you completely lost me when you talked about a different actor not overwriting it. You could simply use conditionals to see if the variable already has a stored value and only save a value if it's already 0.

    Or maybe you don't actually want a global variable, you want something on the actor to reference again?

    Please explain the entire situation in greater detail and you'll be able to get a better answer.
  6. ATT_Turan said:
    I'm confused about what you're trying to achieve. Where do you use this variable? How is it referenced?

    If you actually want a global variable, you should use a global variable:
    Code:
    $gameVariables.setValue(X, a.atk);
    replacing X with the variable's ID, and then you can reference it anyplace else.

    But you completely lost me when you talked about a different actor not overwriting it. You could simply use conditionals to see if the variable already has a stored value and only save a value if it's already 0.

    Or maybe you don't actually want a global variable, you want something on the actor to reference again?

    Please explain the entire situation in greater detail and you'll be able to get a better answer.
    Basically I want a state that buffs an ally's stat based on the Magic Attack of the Actor that applied the state. In my game all stats are between 1 and 100.

    So I want to adjust stats in the state with, for example:

    Code:
    a.atk = a.atk * (1 + origin.mat/100)

    It seems that doing that on its own permanently changes the stat. So I want to save the target Actor's original stat in a global variable that can then be referenced when the state is removed to reset the stat.

    Something like:

    Code:
    <Custom Apply Effect>
    var statAtk = a.atk
    
    a.atk = a.atk * (1 + origin.mat/100)
    </Custom Apply Effect>
    
    <Custom Remove Effect>
    a.atk = statAtk
    </Custom Remove Effect>

    But if I want to be able to apply this state to multiple actors at the same time I think I need to be able to save each actor's original stat in a unique variable to reference in the remove effect part.
  7. You can just add a new property onto an existing object just like that.
    JavaScript:
    <Custom Apply Effect>
    a._originalAtkValue = a.atk;
    
    a.atk = a.atk * (1 + origin.mat/100);
    </Custom Apply Effect>
    
    <Custom Remove Effect>
    a.atk = a._originalAtkValue;
    </Custom Remove Effect>
  8. Nate_Tillern said:
    Basically I want a state that buffs an ally's stat based on the Magic Attack of the Actor that applied the state. In my game all stats are between 1 and 100.

    So I want to adjust stats in the state with, for example:

    Code:
    a.atk = a.atk * (1 + origin.mat/100)
    I would suggest that instead of this entire method, you do it more of the "right" way.

    You should not be directly changing parameters to temporary other values. Instead, use a plugin that allows you to set a statis modifier, such as Quasi Params Plus.
  9. ATT_Turan said:
    I would suggest that instead of this entire method, you do it more of the "right" way.

    You should not be directly changing parameters to temporary other values. Instead, use a plugin that allows you to set a statis modifier, such as Quasi Params Plus.
    Thank you, that plugin is wonderful.

    Out of curiosity, is my initial method considered "wrong" just cause of the potential for really problematic bugs?
  10. ATT_Turan said:
    I would suggest that instead of this entire method, you do it more of the "right" way.

    You should not be directly changing parameters to temporary other values. Instead, use a plugin that allows you to set a statis modifier, such as Quasi Params Plus.
    So unfortunately it seems that Qparams doesn't recognize the origin.X, which is not surprising. The work around I've thought of is saving the state applier's MAT as a variable (v[]) through a common event when they apply a state. However, I have two Actors right now which are both going to be using the same skill to apply the states. Would I have to create two identical skills/states for each Actor so that I wouldn't have them overwriting eachothers' v[] if they both are applying states?

    Or am I missing an easier/more elegant solution?

    Edit/Update:

    So messing around with whether Yanfly's and Quasi's plugins can work together and I got this to seemingly do what I want:


    Code:
    <Custom Apply Effect>
    a.modATK = origin.mat
    </Custom Apply Effect>
    
    <params>
    ATK: a.modATK
    </params>

    I haven't actually put in the actual formulas, but that's just arithmetic which I know will work. However,
    I am curious if this would be considered still a "wrong" way to do it or not?
  11. Nate_Tillern said:
    Code:
    <Custom Apply Effect>
    a.modATK = origin.mat
    </Custom Apply Effect>
    
    <params>
    ATK: a.modATK
    </params>

    I haven't actually put in the actual formulas, but that's just arithmetic which I know will work. However,
    I am curious if this would be considered still a "wrong" way to do it or not?
    Not at all.

    The whole idea is that RPG Maker uses its parameter system for a reason - your actual parameters on an actor are derived from their class and current level. That's it. Everything else (equipment, buffs, states, etc.) goes into several arrays of modifiers that add onto the base parameter.

    The engine doesn't want to touch the base parameters except when the character levels up, changes class, etc. So any time you directly modify those values instead, you run the risk of messing with the character (and with your prior method you were actually overwriting all of that, so if the modifiers changed they while under the state, they wouldn't be reflected). This way works with the parameter modifiers as intended.
  12. Hi, my project's aspect ratio is 16:9.
    In the main menu ther's too much space for the status of the actors, so I was wondering if it was possible to divide the actors into 2 columns.
    In the first column there are the 4 main actors, while in the second all the others (in my project there are more than 10 actors), so in the second column they are in a different size so that they all fit!
    I know that my request is difficult, I would be happy even if only having 2 columns of 4 actors each. :kaopride:
  13. Super015 said:
    I know that my request is difficult
    If you know that your request is difficult, why are you posting in a thread that is explicitly for short and simple questions that don't deserve their own thread?
  14. Sorry, I move my request to a new thread.
  15. Heyo, does anyone know if it's possible to change the bitmap on a Game_Picture without referencing a new file? I'm editing some bitmaps on the fly and would like to be able to draw/move an image based on that new bitmap.

    I've been able to add the bitmap to a Sprite_Picture but Sprite_Picture.picture is null and I don't know how to fill it with something that uses the same bitmap.

    Many thanks!
  16. I need to be able to transfer the player exactly where they were. I have set these switches:
    1664821245303.png

    On the transfer back, the map, x and y are all accurate. However the direction is not, as the sprite invariably faces right. The script call I am using is this:
    Code:
    $gamePlayer.setDirection($gameVariables.value(13))

    Is my code incorrect?
    Thank you.
  17. Terrannus said:
    Heyo, does anyone know if it's possible to change the bitmap on a Game_Picture without referencing a new file? I'm editing some bitmaps on the fly and would like to be able to draw/move an image based on that new bitmap.

    I've been able to add the bitmap to a Sprite_Picture but Sprite_Picture.picture is null and I don't know how to fill it with something that uses the same bitmap.
    I don't really understand your description of what you're trying to do. Are you trying to edit images within RPG Maker?

    If you're saying you've edited the image while the game is open and you want to refresh that...I'm not super knowledgeable about how the caching system works, but you could try changing the bitmap using the same filename to reload it. But I suspect there are better ways to go about whatever it is (like using a screenshot for the game as a lower layer in your image editor).

    Kes said:
    Is my code incorrect?
    No. But you might look at whether something else is temporarily fixing the player's direction, how the actual transfer command you're using works...for me, instead of splitting it into multiple commands, I'd just use the script call for transfer and plug in the stored direction there.
  18. @ATT_Turan I think I'm already doing what you suggest. Here is the transfer command, nothing exotic there as far as I can see which would mess it up.

    1664862795057.png
  19. Kes said:
    I think I'm already doing what you suggest.
    My suggestion was to use the script call, you're using the event command.

    When you pull up that event command, you'll notice there's a setting for what to do with the player's facing direction. My thinking is that having an event command that transfers with some reference to direction and then having the setDirection function call immediately after might be conflicting in some timing.

    Try replacing both lines with:
    $gamePlayer.reserveTransfer($gameVariables.value(7), $gameVariables.value(5), $gameVariables.value(6), $gameVariables.value(13));

    See if that makes any difference. If not, do some error-checking on the value stored in variable 13, make sure it's not being overwritten someplace.
  20. ATT_Turan said:
    If not, do some error-checking on the value stored in variable 13
    This seems to be the issue.
    I had the sprite face left (direction 4) before using the item which effects the transfer. The variable is set on the transfer in to the map. However, when I opened F9 on that map to see what value it had, it had 6 (direction right) which is what is then applied for the transfer back.

    Variable (13) is only ever used for this set of commands. It is in use nowhere else, so I'm at a loss as to where that 6 has come from.

    EDIT
    I tried setting v(13) to zero before setting all the variables for the transfer. After the transfer in F9 still showed 6.
    The game's Search function shows that this variable is used nowhere else, so it's not carrying forward a value from elsewhere.
    I tried changing the variable to v(301) in case somehow (13) was in use in a plugin. Made no difference, still set to 6 (right)

    I suspect this is now not a JS question.