JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 70 of 171 View original ↗
  1. Is there a more elegant way to implement a state that reduces DEF by the caster's ATK. This is wut I got so far, but there are possible flaws w/ this (such as if the caster's ATK changes between when the state was inflicted and when it's removed.
    Code:
    <Custom Apply Effect>
      target._paramPlus[3] -= origin.atk;
    </Custom Apply Effect>
    <Custom Remove Effect>
      target._paramPlus[3] += origin.atk;
    </Custom Remove Effect>
    Ideally, I'd prefer the DEF debuff to be attached to the state and not directly alter the target's stats like in my example. (That way the effects are automatically undone when the state is removed)
  2. I'm working on customizing the message window in my project and I need to offset the text vertically.

    Where does the code set the y position of the text in the message window? I looked for drawtext in the code but couldn't seem to find it as it relates to the message window.

    My problem is a bit complex because I have increased the vertical size of the message window in order to accommodate a larger face picture, but as a result the text itself is moved upwards. Decreasing the size of the window brings the text down to where I want it, but then part of the face picture is cut off.

    I basically would like to know of any way to reposition the text in the message window vertically. I need a method that does not move the face picture. Thus, moving the entire window is out of the question.

    I am using yanfly message core along with its extensions.
  3. @Sardonic It's in the newPage function of Window_Message in rpg_windows.js. So you could just alias the function and set textState.y to whatever you want (in the code below, I've set the text to start one line down). You could also set it to a number or this.lineHeight() * 2, for example.

    I only tried this with Yanfly's Message Core and the first extension. I didn't go through Yanfly's plugins to see if they modified the newPage function or not, but you can copy the code below and put it in a new plugin below Yanfly's plugins.

    Code:
    var Window_Message_newPage_changeY = Window_Message.prototype.newPage;
    Window_Message.prototype.newPage = function(textState) {
        Window_Message_newPage_changeY.call(this, textState);
        textState.y = this.lineHeight();
    };
  4. SeaPhoenix said:
    Code:
    var Window_Message_newPage_changeY = Window_Message.prototype.newPage;
    Window_Message.prototype.newPage = function(textState) {
        Window_Message_newPage_changeY.call(this, textState);
        textState.y = this.lineHeight();
    };
    This worked perfectly, thanks!
  5. Have nary a response in my thread so gonna try my luck here...
    I'm trying to use YEP_MainMenuManager to make a shortcut that goes directly to the skill equip screen instead of going skills -> skill equip. Skill Equip is from YEP_EquipBattleSkills btw. EBStoMMM.png
    I just need help filling out the blanks to create the shortcut.
  6. Quick question: When I create a var within a notetag, can that var be used outside that notetag?
    Example:
    <Custom Initiate Effect>
    var stuff = 420;
    $gameMessage.add('happy ' + stuff);
    </Custom Initiate Effect>
    <Custom Conclude Effect>
    stuff += 1;
    </Custom Conclude Effect>

    This is just a random example I made up, it has nothing to do w/ wut I'm making. I just want to know if the var will persist outside the notetage it was created in, which in this case is <Custom Initiate Effect>
  7. How do I reference attackTimes+ in a damage formula? I've tried "user.attackTimesAdd()" but it doesn't work... I'm just looking for the correct syntax to reference this trait. Thx.
  8. Uuuh, JS quick question...
    Is there a way to measure text width without creating a new bitmap?
    I know Bitmap.measureTextWidth, but I just need the text width in pixel to update in real time.
  9. Kuro DCupu said:
    Uuuh, JS quick question...
    Is there a way to measure text width without creating a new bitmap?
    I know Bitmap.measureTextWidth, but I just need the text width in pixel to update in real time.
    If Bitmap.measureTextWidth is not the width in pixels, what is the measuring unit? I'd also like to know how to measure text width in pixels.
  10. Lanzy said:
    If Bitmap.measureTextWidth is not the width in pixels, what is the measuring unit? I'd also like to know how to measure text width in pixels.

    Uhh, Bitmap.measureTextWidth return text width in pixel. I just thought creating new bitmap just to use that particular function in real time is expensive.
    Or is that already the cheapest way?
  11. Why are you creating a new bitmap just to use it? Presumably if you have something that's displaying text, there's already a Bitmap object there that can call it.
  12. Kuro DCupu said:
    Uhh, Bitmap.measureTextWidth return text width in pixel. I just thought creating new bitmap just to use that particular function in real time is expensive.
    Or is that already the cheapest way?

    ok so I think maybe this could help you:
    There is a Window_Base.prototype.textWidth(text) function, that you can just use anytime during the game. You just have to use any type of window in the game. So for example use a window that is always on the map, if you want to check a text width on a map, like Window_MapNameWindow:

    SceneManager._scene._mapNameWindow.textWidth("hello")

    As long as the window exists in the scene where you want to check the text width you can use that.
  13. While I'm here, I have a question not worth it's own thread:

    How can I add Text to a scene without using windows. Like a simple HUD Text such as "Player Name" on the Map Scene. Is there a way to create a Text Sprite, which has the same properties as a Image Sprite?

    For example, something like this:
    weaponImage = new Sprite(ImageManager.loadMenuWeapon("weapons_ar_goliath_inspect"));
    SceneManager._scene.addChild(weaponImage);

    But with a costum, free floating, non-Window, Text.
  14. @Lanzy
    You can do something like that:
    JavaScript:
    const newSprite = new Sprite();
    newSprite.bitmap = new Bitmap(width,height);
    const text = "Your text here".
    newSprite.bitmap.drawText(text, X, Y, width, lineHeight, 'center')
    SceneManager._scene.addChild(newSprite);

    Example:

    JavaScript:
    const text = "Hello World".
    const newSprite = new Sprite();
    newSprite.bitmap = new Bitmap(200,200);
    newSprite.bitmap.drawText(text, 0, 0, 200, 32, 'center')
    SceneManager._scene.addChild(newSprite);

    You can define the properties fo the Bitmap too, like fontSize, italic etc...
  15. Lanzy said:
    While I'm here, I have a question not worth it's own thread:

    How can I add Text to a scene without using windows. Like a simple HUD Text such as "Player Name" on the Map Scene. Is there a way to create a Text Sprite, which has the same properties as a Image Sprite?

    For example, something like this:
    weaponImage = new Sprite(ImageManager.loadMenuWeapon("weapons_ar_goliath_inspect"));
    SceneManager._scene.addChild(weaponImage);

    But with a costum, free floating, non-Window, Text.

    Not easily. drawText is theoretically callable on any instance of the Bitmap class, but you still need a Bitmap there to draw on. Using transparent windows is the most convenient method if you just want some text on the map screen.

    @Eliaquim's method is a good suggestion too.
  16. Eliaquim said:
    @Lanzy
    You can do something like that:
    JavaScript:
    const newSprite = new Sprite();
    newSprite.bitmap = new Bitmap(width,height);
    const text = "Your text here".
    newSprite.bitmap.drawText(text, X, Y, width, lineHeight, 'center')
    SceneManager._scene.addChild(newSprite);

    Example:

    JavaScript:
    const text = "Hello World".
    const newSprite = new Sprite();
    newSprite.bitmap = new Bitmap(200,200);
    newSprite.bitmap.drawText(text, 0, 0, 200, 32, 'center')
    SceneManager._scene.addChild(newSprite);

    You can define the properties fo the Bitmap too, like fontSize, italic etc...


    I wasn't aware that you need to first create an empty Sprite and then add a Bitmap to it. Thank you for your speedy response!

    Sorry, one more question regarding loading sprites on map:
    Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

    For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
  17. Lanzy said:
    Sorry, one more question regarding loading sprites on map:
    Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

    For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
    The blt (block transfer) function which displays a loaded bitmap on another one takes dw and dh as additional parameters, which allow you to draw it at a bigger/smaller size than the source.
  18. Trihan said:
    The blt (block transfer) function which displays a loaded bitmap on another one takes dw and dh as additional parameters, which allow you to draw it at a bigger/smaller size than the source.

    Muchas gracias!
  19. Lanzy said:
    I wasn't aware that you need to first create an empty Sprite and then add a Bitmap to it. Thank you for your speedy response!

    Sorry, one more question regarding loading sprites on map:
    Can you scale a loaded bitmap to a smaller or larger size and if not, how can you determine its scale before loading it?

    For example I want to display the face of Party Leader in full scale, while the rest of party member's faces are displayed in 70% of original face size.
    You can also use the scale.x and scale.y(or scaleX / scaleY?) Can't remember now, but you can use it to change the scale:
    newSprite.scale.x = 2
    newSprite.scale.y = 2
    The default is 1.
  20. Eliaquim said:
    You can also use the scale.x and scale.y(or scaleX / scaleY?) Can't remember now, but you can use it to change the scale:
    newSprite.scale.x = 2
    newSprite.scale.y = 2
    The default is 1.

    I assume newSprite.scale.x = 1 is 100% size and then 2 would be 200% and so on? And that I need to do before adding the Sprite as a Child or could it also be done after?