Hey
Here's an article which I suggest you read:
To Ruby From C and C++The ? is actually part of the method name. .disposed? is a valid name. Likewise you can put ! at the end of a method name.
Now on to your problem.
You are storing the Window in a local variable. After the script calls you won't have any reference to the object anymore.
After some time the garbage collector removes it. You'll see that as the window disappearing. It can take several seconds. You can force the garbage collector to run with GC.start, but for the general case this is not recommended and inefficient.
What you need to do is to somehow continuously keep a reference to the window.
This can be done in several ways. Among others are an instance variable (@my_msg), a class variable (@@my_msg) or a global variable ($my_msg)
On a side note I suggest you look into some object-oriented design. Your style... Looks like you are used to procedural programming.
Ruby is geared towards object oriented programming. Use its strengths. In your case you could for example create the Msg_Window class in the script editor like this: (replace
my_msg with
self)
class Msg_Window < Window_Message
def set_txt(my_txt)
my_txt_sz = self.contents.text_size(my_txt)
self.opacity = 120
self.contents.draw_text(0, 0, my_txt_sz.width, 32, my_txt)
self.visible = true
end
end
The code for the event could then be something like:
my_msg = Msg_Window.new
my_txt = "Well look what we got here....."
my_msg.set_txt(my_txt)
Well, taking the instance variable solution to call it later we should change the code to:
@my_msg = Msg_Window.new
my_txt = "Well look what we got here....."
@my_msg.set_txt(my_txt)
A possible issue with this is that if you trigger the code again the old window will still be there some time until it is removed by the garbage collector.
Here's a possible way to solve this:
unless @my_msg.nil?
@my_msg.dispose
end
@my_msg = Msg_Window.new
my_txt = "Well look what we got here....."
@my_msg.set_txt(my_txt)
Note: I have only showed you a solution to the problem not the solution. What you should do depends on the situation. Analyze and take the approach you consider to be the best.
*hugs*
~ Zeriab