Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Scripting] Window Won't Appear

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
Okay so since I'm starting to get the hang of Javascript and MV I started making some base to some plugins I want to create. The first one I want to create which I believe will push me to my limits is an Item pop up plugin. I know there is already plugins for this but they aren't what I'm looking for and I want to learn how to make my own anyways. I started the base of this plugin last night after watching @eivl stream and I'm not recieving any errors but my window is not appearing when I call it from script call in the game.

Anyways first things first is what I have . This script is based off of Window_MapName from the core scripts. I don't have any parameters sccripted into this yet because I want to debug and test to make sure I got the core of it working before I make some parameters.

JavaScript:
//=============================================================================
// New Window* Item Popper
//=============================================================================
function Window_ItemPopper() {
this.initialize.apply(this,arguments);
}
Window_ItemPopper.prototype = Object.create(Window_Base.prototype);
Window_ItemPopper.prototype.constructor = Window_ItemPopper;
Window_ItemPopper.prototype.initialize = function() {
    var wiidth = 200;
    var height = 150;
    Window_Base.prototype.initialize.call(this, 5, 5, wiidth, height);
    this.opacity = 0;
    this.Popper_Opacity = 0;
    this._showTimer = 0;
    this.refresh();
};

Window_ItemPopper.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    if (this._showTimer > 0) {
        this.updateFadeIn();
        this._showTimer--;
    } else {
        this.updateFadeOut();
    }
};

Window_ItemPopper.prototype.updateFadeIn = function() {
    this.Popper_Opacity += 16;
};

Window_ItemPopper.prototype.updateFadeOut = function() {
    this.Popper_Opacity -= 16;
};

Window_ItemPopper.prototype.open = function() {
    this.refresh();
    this._showTimer = 150;
};

Window_ItemPopper.prototype.close = function() {
    this._showTimer = 0;
};

Window_ItemPopper.prototype.refresh = function() {
    this.contents.clear();
        var width = this.contentsWidth();
        this.drawBackground(0, 0, width, this.lineHeight());
        this.drawText('Yo Yo What is up yallllllllll, Items Here, & Icon', 5, 5, width, 'center');
        console.log("Created A Winodw");
};

Window_ItemPopper.prototype.drawBackground = function(x, y, width, height) {
    var color1 = 'rgba(0, 0, 0, 0.6)';
    var color2 = 'rgba(0, 0, 0, 0)';
    this.contents.gradientFillRect(x, y, width / 2, height, color2, color1);
    this.contents.gradientFillRect(x + width / 2, y, width / 2, height, color1, color2);
};
Basically it works great, no errors or anything but when I do a script call in one of my NPCs.. this script call to be exact.
Code:
new Window_ItemPopper();
The code runs and my console displays " Created A Window" that I implemented in the refresh function but the window don't appear on my map scene, nothing happens except for the small console output I scripted in.
I'm sure I'm missing something right in front of me but considering I'm new to the JS & RM scripting scene I can't quite see what I'm missing. Any help would be appreciated.
 

eivl

Local Hero
Xy$
0.00
this.opacity = 0;

looks like this never changes.
[doublepost=1447416347,1447412762][/doublepost]And in what scene are you drawing this? you have only linked your Window_Base
[doublepost=1447416672][/doublepost]examples of this: Scene_MenuBase.prototype
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Do I need a scene to draw the window ? I thought you could just draw the window using a script call on an event " new Window_ItemPopper(): . So maybe I do need to create a scene first, I will see what I can do and be back.
Also the opacity I have tried everything with that from changing it to 255 and completely removing it and that never changed anything. I have also removed all other functions except for the basis of a window and still nothing showed up so I'm going to try putting it into a scene and calling the scene see how that works out for me.

Just the code without the other functions I tried yesterday.
JavaScript:
//=============================================================================
// New Window* Item Popper
//=============================================================================
function Window_ItemPopper() {
this.initialize.apply(this,arguments);
}
Window_ItemPopper.prototype = Object.create(Window_Base.prototype);

Window_ItemPopper.prototype.constructor = Window_ItemPopper;

Window_ItemPopper.prototype.initialize = function() {
    console.log('initialized')
    var wiidth = 200;
    var height = 150;
    Window_Base.prototype.initialize.call(this, 5, 5, wiidth, height);
    this.refresh();
};

Window_ItemPopper.prototype.refresh = function() {
    this.contents.clear();
        var width = this.contentsWidth();
        this.drawBackground(0, 0, width, this.lineHeight());
        this.drawText('Yo Yo What is up yallllllllll, Items Here, & Icon', 5, 5, width, 'center');
        console.log("Created A Winodw");
};

Window_ItemPopper.prototype.drawBackground = function(x, y, width, height) {
    var color1 = 'rgba(0, 0, 0, 0.6)';
    var color2 = 'rgba(0, 0, 0, 0)';
    this.contents.gradientFillRect(x, y, width / 2, height, color2, color1);
    this.contents.gradientFillRect(x + width / 2, y, width / 2, height, color1, color2);
      console.log("Drew Background");
};
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
You will need a scene where you will overhaul the window. If you look at Window_MenuCommand, Window_Gold, Window_MenuStatus, they are not automatically drawn in the menu. They are called in the Scene where they belong, and that is where they are being called.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm busy all weekend I never got a chance yet. I will report back when I have done do it, if I can do it lol
[doublepost=1447629646,1447548338][/doublepost]Okay so I got the scene created and the window to appear kind of lol. Now the problem is that when the scene is called the screen turns black, and the text appears in the top left. What I am looking to do is have a small window just like the Map Name Window that displays in the top left of the screen, the game continues on and it's more like a quick notification for the user. So I figured I will add a function to the Scene_Map which will call my Window_ItemPopper and display the information in the top left of the screen. I have done this but now its pushing out the error function undefined whenever I call the function this.createItemPopper(); So I guess I have a few questions, why am I receiving this error?, and is creating a new function for the Scene_Map the right way to go for what I'm looking to do?
Here is my current code. The createItemPopper function is at the bottom of my script so far.
I hope I'm making sense and this is not too much trouble.
Thanks :D
JavaScript:
//=============================================================================
// New Window* Item Popper
//=============================================================================
function Window_ItemPopper() {
this.initialize.apply(this,arguments);
}
Window_ItemPopper.prototype = Object.create(Window_Base.prototype);

Window_ItemPopper.prototype.constructor = Window_ItemPopper;

Window_ItemPopper.prototype.initialize = function() {
    console.log('initialized')
    var wiidth = 200;
    var height = 150;
    Window_Base.prototype.initialize.call(this, 5, 5, wiidth, height);
    this.opacity = 0;
    this.Popper_Opacity = 255
    this._showTimer = 0;
    this.refresh();
};

Window_ItemPopper.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    if (this._showTimer > 0) {
        this.updateFadeIn();
        console.log("Countdown Started");
        this._showTimer--;
        console.log(_showTimer)
    } else {
        this.updateFadeOut();
    }
};

Window_ItemPopper.prototype.updateFadeIn = function() {
    this.Popper_Opacity += 16;
};

Window_ItemPopper.prototype.updateFadeOut = function() {
    this.Popper_Opacity -= 16;
};

Window_ItemPopper.prototype.open = function() {
    this.refresh();
    this._showTimer = 150;
};

Window_ItemPopper.prototype.close = function() {
    this._showTimer = 0;
};

Window_ItemPopper.prototype.refresh = function() {
    this.contents.clear();
        var width = this.contentsWidth();
        this.drawBackground(0, 0, width, this.lineHeight());
        this.drawTextEx('Yo Yo What is up?, Items Here, & Icon', 5, 5, width, 'center');
        console.log("Created A Winodw");
};

Window_ItemPopper.prototype.drawBackground = function(x, y, width, height) {
    var color1 = 'rgba(0, 0, 0, 0.6)';
    var color2 = 'rgba(0, 0, 0, 0)';
    this.contents.gradientFillRect(x, y, width / 2, height, color2, color1);
    this.contents.gradientFillRect(x + width / 2, y, width / 2, height, color1, color2);
      console.log("Drew Background");
};

// =============================================================================
// Add Function To Scene Map
// =============================================================================
Scene_Map.prototype.createItemPopper = function() {
    this._ItemPopper = new Window_ItemPopper(0,0);
    this.addChild(this._ItemPopper);
};
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Sadly, most of the things in your Window is wrong. Also, if you want it to be displayed on the screen, you'd have to place it under the create function first in the Scene_Map, then update to make sure the window gets refreshed per frame. For more information about drawing windows, please do watch:

 

LTN Games

Master Mind
Resource Team
Xy$
0.01
The window I created is basically a copy of Window_MapName, because I want the fade in and out effect it contains. Tonight I will do some basic windows and scenes while I follow your tutorial maybe this will help me more.
[doublepost=1447639120,1447632934][/doublepost]So I watched your tutorial and did a an entirely new script I went over your last post and I ended up getting a window to appear on the scene map and stay there. All I did was did the basic window from your tutorial then after reading your last post I created my normal createItemPopper function and called it in an aliased SceneMap update function, I'm not going to keep it in the update function but I will be playing with my new found knowledge to see what I can come up with. I am going to mark this as solved and lock it, if I have further questions I will start a new topic. Thank you very much for your help it was exactly what I needed. here is the script in case anyone wants to see it.
P.S If you really want to add to this topic please PM me with what you had to say.

JavaScript:
// =============================================================================
// New Method:Scene Map Create Item Popper
// =============================================================================
Scene_Map.prototype.createItemPopper = function() {
    this._ItemPopper = new Window_ItemPopper(0,0);
    this.addChild(this._ItemPopper);
};
// =============================================================================
// Alias Nethod: Scene_Map Update
// =============================================================================
LTN.ItemPopper_MapUpdate = Scene_Map.prototype.update
// =============================================================================
Scene_Map.prototype.update = function() {
  this.createItemPopper();
  LTN.ItemPopper_MapUpdate.call(this)  // Call Alias function
}
//=============================================================================
// New Window* Item Popper
//=============================================================================
function Window_ItemPopper() {
    this.initialize.apply(this, arguments);
}

Window_ItemPopper.prototype = Object.create(Window_Base.prototype);
Window_ItemPopper.prototype.constructor = Window_ItemPopper;

Window_ItemPopper.prototype.initialize = function(x, y) {
    var width = 240;
    var height = 150;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
};

Window_ItemPopper.prototype.refresh = function() {
    var x = this.textPadding();
    var width = this.contents.width - this.textPadding() * 2;
    this.contents.clear();
    this.drawTextEx("Hello Everyone", 0, 0);
};


Window_ItemPopper.prototype.open = function() {
    this.refresh();
    Window_Base.prototype.open.call(this);
};
 
Last edited:
Status
Not open for further replies.
Top