disposed window?

Recently, I wanted to create a script.


How does it work?

@window = Window_textbox.new
@window.event_text("event!")


If you enter the script as above, you wanted to set the length of the sentence in parentheses in @window.event_text to the width of the text box.

However, when I created and ran the script, there was an error called disposed window.

The script is as follows.

class Window_textbox < Window_Base
def initialize(x = 256,y = 192,width = cal_width(), height = 50)

super(x,y,width,height)


end



def event_text(text)
return unless text.is_a?(String)
draw_text(text, 0, 0, 128, 25)
end


def draw_text(text, x, y, text_width, text_height, aligment = 0)
contents.draw_text(x, y, text_width, text_height, text, aligment)



end
end

def cal_width()
bt = Bitmap.new(1, 1)
rect= bt.text_size(contents.draw_text)
bt.dispose
return rect.width
end



I don't know how to fix it. Please help me.
where did you store your script, and where and when did you call it?

one of the mistakes many new programmers make is to believe that they can enter and call their scripts everywhere, but that doesn't work.
where did you store your script, and where and when did you call it?

one of the mistakes many new programmers make is to believe that they can enter and call their scripts everywhere, but that doesn't work.
I put it under the material of the script editor.

And when I called the script, I called it an event on the map.

Create events on the map (auto-run), and then script them

@window = Window_textbox.new
@window.event_text("event!")

That's how it went this way.



And additionally, how do I make the window disappear when I press a specific key after creating the box?

def dispose2
contents.dispose unless disposed? if Input.trigger?🙂C)
super
end

I've made it this way, but it doesn't work.

Thank you for your answer.
if Input.trigger?🙂C)
is if Input trigger?( :C) // ( and : is attached.
first of all: what exactly are you trying to accomplish here?
first of all: what exactly are you trying to accomplish here?
I thought that the width of the window changes according to the length of the sentence.

And I thought that it would disappear if I pressed a particular button while the window was showing.
while the window was showing.
that is a condition that involves another process.
have you read the code to find that other process?
that is a condition that involves another process.
have you read the code to find that other process?
If you're asking about the process of determining if a window is visible, you're not.

* I'm sorry. I'm not sure what exactly you mean by your question.
the window is held open while the text is displayed, and kept closed when there is no text to display.
do you know where that check comes from? that is the other process.

no point explaining how to do this if you don't understand the code you're reading.

Original thread: https://forums.rpgmakerweb.com/threads/disposed-window.150236/