Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Scene_Map problem

Hi there, im creating a log of my own that is linked into scene_map. It creates a window in it and then data is transferred to the window. But my problem seems to be, the data that is transferred to it doesn't stay, it disappears. I'll guide you along maybe you can spot the problem i have missed.
Scene_Map Addition:
Code:
@my_window = Window_Log.new
#disposed
@my_window.dispose
#updated
@my_window.update
Then there is my Window:
Code:
class Window_Log < Window_Base
  attr_accessor   :text
  def initialize
    super(0, 275, 210, 100)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = "Arial"  
    self.contents.font.size = 15
    self.opacity = 0
    refresh(" ")
  end
  def refresh(text)
    @text = text
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 45, 300, 32, "This is Text: " + @text)
  end
end
Then i called it of course:
Code:
object = Window_Log.new
object.refresh('hello')

On screen this happens:
This is text:
#called it
This is text: hello
#10 seconds later
This is text:

Can anyone tell me why this is?
 
I think it's because you've already create Window_Log in Scene_Map already, which is @my_window. This @my_window when created, it is refresh with a string of " ". And this one gets to update every frame since you also update it in Scene_Map

However, you create another object from Window_Log class and refresh it with a string of "hello". Now you have two Window_Logs, with object is over @my_window. The Window_Log with the name "object" doesn't get update every frame, so it's gone, leaving only @my_window with no text on it.

I'd suggest you to write another method in Scene_Map, say, "send_data_to_log(string)" and in there you refresh the @my_window with string

Code:
def send_data_to_log(string)
  @my_window.refresh(string)
end

And then you can call this script from an event
Code:
$scene.send_data_to_log(Whatever data you want to send)

I haven't tried this, but I think it'll work.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top