JavaScript questions that don't deserve their own thread

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
943
Reaction score
593
First Language
English
Primarily Uses
RMMV
sure can. here's an event:
upload_2017-5-22_17-4-31.png

Here's the text scroll:
upload_2017-5-22_17-5-13.png

And a message window for good measure:
upload_2017-5-22_17-5-33.png
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
697
Reaction score
624
First Language
German
Primarily Uses
RMMV
@ramza
Code:
Window_ScrollText.prototype.refresh = function () {
   var textState = { index: 0 };
   textState.text = this.convertEscapeCharacters(this._text);
   this.resetFontSettings();
   this._allTextHeight = this.calcTextHeight(textState, true);
   this.createContents();
   this.origin.y = -this.height;
   var text = this._text;
   var tw = this.textWidthEx(text);
   var textX = (Graphics.boxWidth / 2) - (tw / 2);
   this.drawTextEx(text, textX, 1);
};

With that the text in the textbox should not go further than the "grey line", otherwise it get's cut off.
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
943
Reaction score
593
First Language
English
Primarily Uses
RMMV
It does work as advertised:
upload_2017-5-22_17-51-38.png
upload_2017-5-22_17-48-21.png

But I would like for the origin to be at 168 pixels, which is what the message window ends up at when I make it 816 pixels wide. When I changed your script to draw at exactly 168 pixels, the text continued until the edge of the screen again, instead of where the grey bar was.
Code:
Window_ScrollText.prototype.refresh = function () {
   var textState = { index: 0 };
   textState.text = this.convertEscapeCharacters(this._text);
   this.resetFontSettings();
   this._allTextHeight = this.calcTextHeight(textState, true);
   this.createContents();
   this.origin.y = -this.height;
   var text = this._text;
   var tw = this.textWidthEx(text);
   var textX = 168 // (Graphics.boxWidth / 2) - (tw / 2);
   this.drawTextEx(text, textX, 1);
};

upload_2017-5-22_17-51-8.png
If I'm understanding this correctly, can we not just draw the textscroll in a window box that is 816 wide by screenheight high? or does that not work? I mean, I can dow ithout the cutoff on the grey line, as I had to deal with that already due to the change of font size, (note that the top box shows the line on the word 'of', but the cutoff is actually several words later).
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
697
Reaction score
624
First Language
German
Primarily Uses
RMMV
You could modify the x position and width of the scroll window instead.
Code:
Scene_Map.prototype.createScrollTextWindow = function() {
    this._scrollTextWindow = new Window_ScrollText();
    this._scrollTextWindow.x = 168;
    this._scrollTextWindow.width = 816;
    this.addWindow(this._scrollTextWindow);
};
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
943
Reaction score
593
First Language
English
Primarily Uses
RMMV
There we go, that's exactly what I was looking for. Thanks.
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
260
Reaction score
71
Primarily Uses
So, here's an incredibly stupid question.



I'm trying to resize the command window to fit inside of the orange borders, more or less. However, I couldn't get the commands to appear horizontally using MOGs BattleHUD, so I modified the visible rows/columns using a custom plugin. But, I can't adjust the height of the window in order to make it less "click these words" and more "click this button." Adjusting the height does.. well, nothing, really. I've made it 500, I've made it 100.. Doesn't really do anything. The only thing that I can think of is that the height command isn't the literal WxH type of Height, but X/Y/Z height. Am I on the right track, or is there some sort of conflicting plugin shenanigans occurring here?
 

Attachments

  • examplehud.png
    examplehud.png
    13.4 KB · Views: 1

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,711
First Language
Czech
Primarily Uses
RMMV
Height command works fine. But there's a difference between
Command window height
and Command height
You can modify the command window height as much as you like, but it has no influence on the height of commands.
If you want to modify Command height, you'll need to modify the scripts responsible for showing the commands (so rpg_windows.js, if I'm not wrong).
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
260
Reaction score
71
Primarily Uses
This is where the question becomes stupid. If I adjust the width, then the commands become smaller, as expected. But, adjusting the height does nothing past a certain point. For example, should I make the height 1, then the options virtually disappear-- but the difference between 100/1000 isn't noticeable. Is there perhaps some sort of cull that refuses to let the height go past a maximum amount?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,711
First Language
Czech
Primarily Uses
RMMV
By default the command height is equal to this.fittingHeight(1), which in translation means height of up to 1 line.
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
260
Reaction score
71
Primarily Uses
Unfortunately, using this snippet:
Code:
Window_Command.prototype.windowHeight = function() {
    return 3000;
};

Does nothing except cause a longer boot time. I'm going to just assume I'm stupid, and put this problem to the side for now.
 

worshipme

Veteran
Veteran
Joined
Jun 14, 2016
Messages
34
Reaction score
5
First Language
Filipino
Primarily Uses
RMMV
hi guys,

I want to switch off a common event once a state expires, I'm thinking of using Yanfly's Buffs and States Core:

<Custom Leave Effect>
code
code
</Custom Leave Effect>

I just don't know what to put inside the code. Can you please help me?
Thank you in advance...
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,711
First Language
Czech
Primarily Uses
RMMV
@ZServ I looked through the game code and found that
1. you're dumb, because Window_Command.prototype.WindowHeight influences the basic height of a command window (which again has nothing to do with command height), but
2. you're not dumb, because:
The functions that take direct care of battle command window are prototypes of Window_ActorCommand. However, looking through the code I found that it's actually way more complicated than to solve it through change of command height, because it's apparently hidden somewhere in the core scripts and has to do with text rendering, so it's very difficult to enhance command height. I also looked at MOG_Battlecommands for some clues,but there I found that I don't understand it, so I gave up on it.
@worshipme $gameSwitches.value(switchId, true/false) switches off a common event switch.
 
Last edited:

worshipme

Veteran
Veteran
Joined
Jun 14, 2016
Messages
34
Reaction score
5
First Language
Filipino
Primarily Uses
RMMV
@Poryg thank you very much sir. I finally made it to work. I just adjusted it to my need:
$gameSwitches.setValue(1,false)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,711
First Language
Czech
Primarily Uses
RMMV
Sorry, that was autocorrect :)
 

padr81

Guy whose game is taking too long.
Veteran
Joined
Apr 26, 2013
Messages
739
Reaction score
763
First Language
english
Primarily Uses
N/A
Just a quick question. I've put this in my damage formula box and its not working. I'm sure I'm doing something simple wrong but can't put my finger on it.

if b.isStateAffected(12){(a.atk * 4 + a.mat *2 - b.def * 2)} else {a.atk * 4 - b.def * 2}
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,779
Reaction score
2,921
First Language
English
Primarily Uses
RMMZ
If statement conditions have to be enclosed in brackets.
 

padr81

Guy whose game is taking too long.
Veteran
Joined
Apr 26, 2013
Messages
739
Reaction score
763
First Language
english
Primarily Uses
N/A
If statement conditions have to be enclosed in brackets.

Knew it was something silly, lol, wouldn't mind but I was staring at the code for about half an hour like an eejit and not seeing anything wrong. Never entered my head to check the most obvious thing which is usually the correct thing. Thanks dude.
 

cyberchronomage

Villager
Member
Joined
Jul 7, 2014
Messages
5
Reaction score
0
Primarily Uses
I made a plugin to produce a simple window that's specific for an event. The problem is, the window is always up there. I tried to create a plugin command to toggle the window but it doesn't work.

This is the parameter I want to change:
* @param Control Switch
* @desc true = on, false = off
* Default false
* @Default false

This is what I have at the top of the main function:
var parameters = PluginManager.parameters('BPE Lock Pick Window');
var BPEwindowX = Number(parameters['Window X']);
var BPEwindowY = Number(parameters['Window Y']);
var BPEcontrol = String(parameters['Control Switch']).trim() == "true";
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === 'LP_On'){parameters.BPEcontrol = String("true")};

if(command === 'LP_Off'){parameters.BPEcontrol = String("false")};
};

I've tried
if(command === 'LP_On'){BPEcontrol = String("true")};

if(command === 'LP_Off'){BPEcontrol = String("false")};
but nothing changes and the window stays on the screen. Any suggestions would be helpful. The full plugin is here.
 

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
@cyberchronomage Here's a plugin to demonstrate.

Code:
/*
* clockoutLockPickWindow.js
* 2017-06-01
* Copyright (c) 2017 Dominic Herrera
* License: Do anything you want.
* Disclaimer: NO WARRANTY.
*/

/*:
 * @plugindesc Show lock pick count window via plugin command.
 * @author Clock Out
 *
 * @help
 * SYNOPSIS
 *     Toggle the lock pick count window.
 *
 * SYNTAX
 *     LP <ON|OFF>
 *
 * EXAMPLE
 *     LP ON
 */

var clockout = clockout || {};

clockout.window = clockout.window || {};

/**
 * Create a window to track a $gameVariable value.
 * @returns {object} The new window.
 */
clockout.window.lockPickWindow = function () {
    "use strict";

    var config = {
        name: "Lock Pick",
        numLines: 1,
        variableId: 94,
        width: 220,
        x: 530,
        y: 0
    };
    var window = Object.create(Window_Base.prototype);

    window.refresh = function () {
        var x;

        window.contents.clear();

        x = window.drawTextEx(
            config.name,
            0,
            0,
            window.windowWidth(),
            "left"
        );

        window.drawText(
            ":" + $gameVariables.value(config.variableId),
            x + 15,
            0,
            window.textWidth("000"),
            "right"
        );
    };

    window.initialize = (function (alias) {
        return function () {
            alias.apply(this, arguments);

            this.openness = 0;
        };
    }(window.initialize));

    window.update = (function (alias) {
        return function () {
            alias.call(this);
        
            if (this.isOpen()) {
                window.refresh();
            }
        };
    }(window.update));

    window.windowHeight = function () {
        return window.fittingHeight(config.numLines);
    };

    window.windowWidth = function () {
        return config.width;
    };

// Setup the window.

    window.initialize(
            config.x,
            config.y,
            window.windowWidth(),
            window.windowHeight()
        );

    window.refresh();

    return window;
};

// Alias pluginCommand.

(function (alias) {
    "use strict";

    function pluginCommand(command, args) {
        var isLoaded = SceneManager._scene.hasOwnProperty("lockPickWindow");
        var window;

        alias.call(this, command, args);

        if (command !== "LP") {
            return;
        }

        if (isLoaded === false) {
            window = clockout.window.lockPickWindow();

            SceneManager._scene.addWindow(window);
            SceneManager._scene.lockPickWindow = window;
        }

        switch (args[0]) {
        case "ON":
            SceneManager._scene.lockPickWindow.open();
            break;
        case "OFF":
            SceneManager._scene.lockPickWindow.close();
            break;
        }
    }

    Game_Interpreter.prototype.pluginCommand = pluginCommand;
}(Game_Interpreter.prototype.pluginCommand));
 

Latest Threads

Latest Profile Posts

About the Deer, I had to cut some piece of video due the *swearing* Youtube copyrights issues...
I was listening to songs by Chuck E Cheese's voice actor (Jaret Reddick from Bowling for Soup) when the meds I was taking for my stomach virus apparently stopped working. I can't take my next dose until morning, but it's no use anyway. I'm officially sick again. Of course, I'll definitely take the next dose either way, but it's useless now.
New profile picture! This time, it's representative of my current project.
I suddenly feel like making a game for little kids: a pointless sandbox of cute animals, silly collectibles, and random mini games.
Anyone else just like, not bother to make games themed around specific holidays? I know I won't get them done in time for it to make sense.

Forum statistics

Threads
115,992
Messages
1,094,713
Members
151,291
Latest member
nk97
Top