RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
RMXP, Working with Message_Window's.

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 86
Hello,

I have basically made a copy of the Window_Message class (in-case I want to modify the actual class it-self later).

And I have finally come to the point of making this code (it's really hard to find information and the help file isn't exactly informative to say the least....):

Code: [Select]
my_msg = Msg_Window.new
my_txt = "Well look what we got here....."
my_txt_sz = my_msg.contents.text_size(my_txt)

my_msg.opacity = 120
my_msg.contents.draw_text(0, 0, my_txt_sz.width,
32, my_txt)
my_msg.visible = true

For anyone not familiar in whole with this particular code, I have basically setup a variable that creates a new Msg_Window instance (originally Window_Message), setup a variable to contain text, perform text_size function to return a rect (rectangle, x y width and height values of the text), change the window opacity, draw the text with the inclusion of the width being the width return of the text rect (so text all shows in the window) and make the window visible.

All works fine, but how to dispose of it (like give it some time, and then dispose of it, not just right away).

Also if anyone knows if it's possible to do new lines and such within the string and have it display normally, it would also be greatly appreciated.

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
To get rid of a window that has been called, use .dispose to get rid of it. As for when to dispose it, use a looping branch for that. Just add a wait command if you're doing this through events.

**
Rep:
Level 86
I am, but I get errors if I try to use the object outside of the immediate script.

For example I write the bulk of the script, cut out of it, put a wait, new script with dispose, and it complains (I assume as far as it is concerned there is no reference to the object).

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
This post is me assuming you're using the Call Script event command.

Try storing Msg_Window in a game variable. Use $game_variables[index] and for when you dispose it using the game variable, use a branch like this one.

Code: [Select]
if $game_variables[index].disposed? == false
  $game_variables[index].dispose
end

**
Rep:
Level 86
I use the last event command (3rd page bottom right) to directly write scripts in.

Not familiar with these game variables (nor using that question mark in the if statement..... lol).

Never seen it done before?

I guess Ruby wanted to be different huh lol.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
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)
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
@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:
Code: [Select]
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