Disposing of a custom window

mdqp

Veteran
Veteran
Joined
Jun 2, 2014
Messages
45
Reaction score
8
First Language
Italian
Primarily Uses
So, I have a problem which is probably easy to solve, but I can't figure out since I am completely new to scripting:


I wanted to display a window with a message which didn't disappear despite user input, so I added this script:


class Window_Bro < Window_Base
def initialize
super(Graphics.width / 4, 0, Graphics.width / 2, 48)
refresh
end

def refresh
if $game_variables[78] == 1
draw_text( 0, 0, contents_width, contents_height, "Nessa")
else if $game_variables[78] == 2
draw_text( 0, 0, contents_width, contents_height, "Alice", 1)
else
draw_text( 0, 0, contents_width, contents_height, "Liu", 1)
end

end
end
end


I use a script call in-game for when I need it: (@w=Window_Bro.new) but when it comes to make it disappear, I haven't found a way to do it. That also means that calling the window again creates a "stack" of window, with the different text overlapping. So how would I go about deleting and/or refreshing the content of the window?


Edit: Forgot to mention I am using RPG Maker VX Ace.
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Using a script call to make windows directly there is a bad idea.


That means that the window will be created in the event's interpreter (which is an instance of the Game_Interpreter class).


You can lose the reference to these windows easily this way, and that means you won't be able to get rid of them.


If the player doesn't need to move when this window is shown, you could do this:

@mwin = Window_Bro.new
Fiber.yield until Input.trigger?:)C) || Input.trigger?:)B)
Sound.play_ok
@mwin.dispose

This will create the window, wait for player input (confirm or cancel button pressed), and disposes the window after that.


This is also safe to do, because you are disposing it in the same interpreter instance you created it.


If you want to allow player movement when the window is shown, you should create the window in the scene itself, and make a script call to trigger the window there instead.


You will still need to maintain a disposal logic (in case there is already a shown window when a new one is triggered, you will need to dispose the old one before making another), but your window will be an a class where you can always access it without the fear of losing the reference to it.


If you need to update the content of the window in real time, you will have to add your refresh method into the window's update method, and you will need to make a condition for it, so that it only draws the data when it really needs to (otherwise it will impact performance way more than it should).
 

mdqp

Veteran
Veteran
Joined
Jun 2, 2014
Messages
45
Reaction score
8
First Language
Italian
Primarily Uses
Is it really impossible to delete a window after you create it in the event's interpreter?


Anyway, I think I can do it by modifying your example a little (although in the future I might have to make the window in the scene, since I might want the player to be able to move), thank you very much for your help! :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,047
Messages
1,018,539
Members
137,834
Latest member
EverNoir
Top