Creating Custom Windows In Events Using Script Calls

Zekarius

Villager
Member
Joined
Feb 13, 2016
Messages
6
Reaction score
2
First Language
English
Primarily Uses
Hi, my name is Zekarius, and I have been using RPGMaker since VXAce. I was starting to get really proficient with ruby and then, just recently, I acquired MV to see if the more powerful graphics engine and whatnot was worth making games in. I have decided I would like to make games in MV but the scripting is really throwing me for a loop. One thing I loved to do whilemaking games in VXAce was using events that called scripts to make custom face graphics for the message window, as seen in this VXAce tutorial here: http://forums.rpgmakerweb.com/index.php?/topic/38406-eventing-tutorial-for-creating-custom-text-windows/&_fromLogin=1#replyForm


I cannot seem to replicate this in MV (or really make any scripting work) even though I am rather familiar with javascript. I have tried something like:


var x = Graphics.width * 1/5 + 4;
var msgwindow_height = new Window_Message.windowHeight();
var y = Graphics.height - (2 * msgwindow_height) + 4;
var w = 120;
var h = 120;
var win = new Window_Base(x, y, w, h);
win.drawFace("Nature", 5, 0, 0);


by calling it inside an event, but this just gets me an error message saying that "undefined is not a function." I would greatly appreciate if anyone could point me in the right direction or even give me some things to try. After seeing the beautiful windows and whatnot, I would really hate to have to go back to VXAce just because I can't make the code work for me in MV.
 
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,790
Reaction score
7,876
First Language
German
Primarily Uses
RMMV
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.


MV is for regular support, and a lot of the people browsing this aren't deep enough into javascript to be able to help you.
 

DreamX

Veteran
Veteran
Joined
May 30, 2015
Messages
816
Reaction score
828
First Language
English
Primarily Uses
Turn on the console and show us the full error messages.
 

Zekarius

Villager
Member
Joined
Feb 13, 2016
Messages
6
Reaction score
2
First Language
English
Primarily Uses
Okay, so, I ran the code in an event, turned on the console with F8, and this is what I got from the debugger:

Code:
TypeError: undefined is not a function
    at Game_Interpreter.eval (eval at <anonymous> (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:10439:10), <anonymous>:2:24)
    at Game_Interpreter.command355 (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:10439:5)
    at Game_Interpreter.executeCommand (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:8897:34)
    at Game_Interpreter.update (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:8805:19)
    at Game_Map.updateInterpreter (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:6082:27)
    at Game_Map.update (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_objects.js:5989:14)
    at Scene_Map.updateMain (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_scenes.js:417:14)
    at Scene_Map.updateMainMultiply (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_scenes.js:409:10)
    at Scene_Map.update (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_scenes.js:398:10)
    at Function.SceneManager.updateScene (file:///C:/Users/lukea/Documents/RPGMaker/MV/Test1/js/rpg_managers.js:1788:25)
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
724
Reaction score
581
First Language
French
Primarily Uses
Okay, so first:


Unlike in ruby, you need a function to make your window appear on the map.


Here is a basic script that will add a window to the current scene and draw some text in it.


var win = new Window_Base(150, 150, 100, 100); //x,y,width,height
SceneManager._scene.addChild(win) //adds the window to the curent scene
win.drawText("Your text", 0, 0, 100, "left"); //draws the text




I'm also having difficulties drawing a Face. My first call of the script doesn't draw a face, just an empty window but my second draws a new window and a face as expected.


if ($gameVariables.value(1)) {SceneManager._scene.removeChild($gameVariables.value(1)}
var win = new Window_Base(100, 100, 300, 300);
SceneManager._scene.addChild(win)
$gameVariables.setValue(1,win)
win.drawFace("Nature",0 ,0 ,50)
win.update() // I've tried with and without that and it doesn't seem to do anything


This draws an empty window on the first call, then on subsequent call a window with the proper face drawn in it. Easy fix: run the code twice  :). But that would be admitting defeat, there must be a logical explanation.


(You can see I set win inside game variable 1, in order to not draw multiples of the same window).


Next: Your calculations are fine but you cannot do it like this. You have to first set up the new window message inside a variable, then retrieve it's height.


Here works:


var x = Graphics.width * 1/5 + 4;
var msgWindow = new Window_Message //Setting up the msg window
var msgwindow_height = msgWindow.height //retreiving its height. As you can see: height is not a function but a property.
//That's one of the reasons for the errors.
var y = Graphics.height - (2 * msgwindow_height) + 4;
var w = 120;
var h = 120;

if ($gameVariables.value(1)) {SceneManager._scene.removeChild($gameVariables.value(1))}
//if there is already a window inside variable 1, remove it from the current scene.

var win = new Window_Base(x, y, w, h);
SceneManager._scene.addChild(win)
$gameVariables.setValue(1,win)
win.drawFace("Nature",0 ,0 ,0 ,w ,h) // specify the width and height or the picture will be cropped


This is the result upon the second call of the script:





The first returns an empty window and i cannot fathom why.


Edit: Ah I just realized that windowHeight is indeed a function inside window base. However to my understanding it seems to be made to give the window the appropriate height for a message, not to return the window height.
 
Last edited by a moderator:

Zekarius

Villager
Member
Joined
Feb 13, 2016
Messages
6
Reaction score
2
First Language
English
Primarily Uses
@Astfgl66  Thank you so much for the thorough response. I will report back here after trying a few more things and running some more tests of my own. I guess I just got way too used to being able to do a lot of stuff at once in Ruby and didn't think that JS wouldn't have the same flexibility. Anyways, I'll report back tomorrow (or maybe Saturday.) I'm gonna try and figure out why it doesn't draw the face at first glance. As you said, there must be a logical explanation.
 

Zekarius

Villager
Member
Joined
Feb 13, 2016
Messages
6
Reaction score
2
First Language
English
Primarily Uses
I HAVE FINALLY DONE IT! Phew, it took over a month but I finally figured out what the problem is.

The face image is not pre-loaded when you hit the map. The window gets drawn, discovers the image isn't loaded and instead of freezing and waiting like previous games, just loads the image for next time.

All I had to do was run an autorun event with a single line of code in a script call in it.


ImageManager.loadFace("Nature");


This told the image manager to load the face file with the name "Nature" so it could be used later on the map and voila! The face I wanted pops up the first time using the code figured out in the previous post! This isn't going to solve all of the problems, and now that I know what I'm doing a bit better, it really might be easier to use plugin commands for this, but as for a quick fix, we finally found it. Thanks everyone who helped. For me, this particular thread is solved.
 

jayray

Jay Ray Games and Art Design- Oklahoma City, OK
Veteran
Joined
Oct 13, 2013
Messages
136
Reaction score
97
First Language
English
Primarily Uses
RMMV
how to close the window once it's created? (I've asked in another thread but have no answer yet)
 

dwiseman57

Merchant Prince Digital
Veteran
Joined
Jun 29, 2014
Messages
40
Reaction score
1
First Language
English
Primarily Uses
N/A
I also would like to know how to close the window once opened
 

Latest Threads

Latest Posts

Latest Profile Posts

I remember once when I was at Disney's Animal Kingdom and I got to dance with some of the cast members! It was so much fun! After the show my dad and I got frozen lemonade and some ice cream. It makes me feel better remembering the good things about my dad... maybe I will return to Orlando.
spending almost entire day to mod skyrim but it still couldn't run properly :(
My friend has become one with the glitter. @ImaginaryVillain, got any room in the Cult of the Sporkle?
I still cannot wrap my head around how to edit and use arrays in RPG Maker MV o_O
Gamemaking has been slower, but I do my best to make small progress every day. :)

Forum statistics

Threads
107,717
Messages
1,031,634
Members
139,857
Latest member
ShadowGray
Top