Ruby/RGSSx questions that don't deserve their own thread

This is a common misconception between scripters. I had the same issue as you when I started scripting and the solution is not that simple. While in events you can easily call the wait command without stopping all the processing, scripts behave in a different way. 

You can do something like that:

class Scene_Base  alias milena_update update  alias milena_terminate terminate  def update    milena_update    update_momotaros if @character_motion != nil  end  def terminate    if @character_motion != nil      @character_motion.dispose      @character_motion = nil    end     milena_terminate  end  def create_momotaros(momo)    momo_x = get_motion(0)    @character_motion = NPC_TkboxWindow.new(momo_x, momo)    @character_motion.visible = true    @character_motion.update_pos(momo_x)    @wait_milena = 5  end  def update_momotaros     if @wait_milena > 0      @wait_milena -= 1    else      @character_motion.dispose      @character_motion = nil    end  endendSo, you call SceneManager.scene.create_momotaros(momo) to call your method
When 5 frames pass, the window will be automatically disposed.
Also, if the scene you are currently in terminates, the window will also be disposed (you can't have windows, sprites and bitmaps messing around - you need to dispose them when they finish their job).

Please note that this isn't the best solution - but it works, and should encourage you to find better ones.
I just noticed your solution. Thank you very much and I will try this out. 🙂

Okay, so I have tried it out. Somehow, the box that should appear on top of the character does not show. This is my momotaros class. The scene works but the error is in this class:

class NPC_TkboxWindow < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(npc, txt) super(0, 0, 100, 50) self.z = 90 contents.draw_text(0, 0, 100, 30, txt) self.visible = false end def update_pos(npc) self.x = npc.screen_x-47 self.y = npc.screen_y-84 update endendIt says it doesn't know the screen x and screen y methods.
If you are passing a Game_CharacterBase object it should have these methods. Unless npc is nil. You can insert @npc = npc in your initialize method, and then use @npc in your update_pos method, discarding the need of an argument.
Somehow, it does not pull any Game_CharacterBase at the moment. I am reading my friend's old article and this is what I came across with his tutorial. Anyway, this is my class:

Spoiler
class NPC_TkboxWindow < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(txt) super(0, 0, 100, 50) self.z = 90 @npc = npc contents.draw_text(0, 0, 100, 30, txt) self.visible = false end def update_pos(npc) self.x = npc.screen_x-47 self.y = npc.screen_y-84 update endendclass Game_System attr_accessor :momotaros_message alias milena_npctalkbox_initialize initialize def initialize milena_npctalkbox_initialize # Call original method @momotaros_message = 0 end endclass Game_Interpreter #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update @fiber.resume if @fiber $game_system.momotaros_message = get_character(0) end endclass Scene_Base attr_accessor :npc_textbox attr_accessor :message alias milena_update update alias milena_terminate terminate def update milena_update update_momotaros if @npc_textbox != nil end def terminate if @npc_textbox != nil @npc_textbox.dispose @npc_textbox = nil end milena_terminate end def create_talkbox(message) @npc_textbox = NPC_TkboxWindow.new(momotaros_message,message) @npc_textbox.visible = true @npc_textbox.update_pos($game_system.momotaros_message) end def update_talkbox if @wait_message > 0 @wait_message -= 1 else @npc_textbox.dispose @npc_textbox = nil end endend 
What could have I done wrong?
When you initialize your TkboxWindow, you have only one argument, but in the scene itself you called it with 2 arguments.

That alone should have throw you an argument error.

When Khas wrote that you could use a @ before the npc argument, he meant that you can remove that argument in the 'update_pos' method of your window, not in the initialization method.

Like this:

class NPC_TkboxWindow < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(npc,txt) super(0, 0, 100, 50) self.z = 90 @npc = npc contents.draw_text(0, 0, 100, 30, txt) self.visible = false end def update_pos self.x = @npc.screen_x-47 self.y = @npc.screen_y-84 update endendCalling self.visible = false in the initialization of the window class just to call @window.visible = true immediately when the window appears is not needed. Remove both visible calls.You can't simply put something like that in an update method, especially not in Game_Interpreter.

You call the script line you entered there in the event itself immediately before calling the window itself. That way it will surely get the right character.

Calling 'get_character(0)' will get you the currently executing event character. If there is no event being executed, there won't be a character to get, hence your momo will be nil. And that is why you get no character for your window.

So, call '$game_system.momotaros_message = get_character(0)' in the event you want to call the window. Do it before you call the window. That should get the character for your window.

That should get you the character. I wonder what you want to achieve. A window which moves with the event if the event moves? I highly doubt that that will work with your script...

I might just try it out to see. 😀
I am trying to show dialogues on the screen on top of the character. The script call goes: 

SceneManager.scene.create_talkbox("Dude")and the npc will show the Dude word on the screen.
Here is one working version:

Spoiler
class NPC_TkboxWindow < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(npc,txt) super(0, 0, 100, 50) self.z = 90 @npc = npc contents.draw_text(0, 0, 100, 30, txt) self.visible = false end def update super update_pos end def update_pos if self.x != @npc.screen_x-47 || self.y != @npc.screen_y-84 self.x = @npc.screen_x-47 self.y = @npc.screen_y-84 end end endclass Game_System attr_accessor :momotaros_message alias milena_npctalkbox_initialize initialize def initialize milena_npctalkbox_initialize # Call original method @momotaros_message = 0 end endclass Game_Interpreter #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update @fiber.resume if @fiber $game_system.momotaros_message = get_character(0) end endclass Scene_Base attr_accessor :npc_textbox attr_accessor :message alias milena_update update alias milena_terminate terminate def update milena_update update_talkbox if @npc_textbox != nil end def terminate if @npc_textbox != nil @npc_textbox.dispose @npc_textbox = nil end milena_terminate end def create_talkbox(message,wait) @npc_textbox = NPC_TkboxWindow.new($game_system.momotaros_message,message) @wait_message = wait @npc_textbox.visible = true end def update_talkbox if @wait_message > 0 @wait_message -= 1 else @npc_textbox.dispose @npc_textbox = nil end endend
But this got one flaw for sure.

If there will be more windows like this on the screen, not all of them will be properly disposed. Sometimes, if you spawn a lot at once, the windows will stay on the screen forever.

The other problem with your code was, that you wanted to allow the player to move during these messages. In this case, screen_x and screen_y won't work unless you update the window's x and y position when the event's screen_x and screen_y changed.

If you won't update it, the window will follow the screen and won't stay at the event's position.

I changed this in your code.

I also added another argument in your script call, so that you can specify the wait time for your windows on a per window basis.

You realize that 5 frames is not even a blink of an eye, right? 😀

So, the first argument is the text, the second is the wait time in frames.

You might want to make a method which will scale the window to the text itself, rather than staying static, or add 2 other arguments to the script call, so you can enter different width and height for the windows.

Just my suggestions. 😛

It's a cool idea, btw.
Thanks for the script correction. By the way, it says I have only 1 argument instead of 2 as an error. What is the correct script call?
SceneManager.scene.create_talkbox("text",time)This is the correct script call.
Replace the text with your text and the time with the amount of frames you want the window to be on the screen. 60 is 1 second, 600 is 10 seconds, and so on.
It has another error. Screen x is not defined :\

The error is thrown here:

Code:
  def update_pos    if self.x != @npc.screen_x-47 || self.y != @npc.screen_y-84      self.x = @npc.screen_x-47      self.y = @npc.screen_y-84    end  end
Yes, I forgot that I set the $game_system.momotaros_message just before I called that script call.

That is why I wrote that that line in Game_Interpreter you added is kinda useless unless an event is running.

But if you set the event before the above mentioned script call like this:

$game_system.momotaros_message = $game_map.events[@event_id]SceneManager.scene.create_talkbox("Dude",600)Than it will work.Now, if you want to shorten this script call, that is why Game_Interpreter is there for us.

Add this little snippet at the end of your script:

class Game_Interpreter def create_talkbox(text,time) $game_system.momotaros_message = $game_map.events[@event_id] SceneManager.scene.create_talkbox(text,time) end endNow you can simply call 'create_talkbox("text",time)' and it will work.Just remember that with the current code you got, calling more than one window will get you bugs.
Yes, I was thinking of the same thing for the script call. The script becomes long and takes more errors, so making a method on the interpreter becomes the best solution. Thank you very much. I wish my friend would update this script and somehow come along the wall you mentioned where it might have its errors.
im using this :
module TitleMenu
 
   MAIN_IMAGE   = "mainmenu"
   
  
end 
 
 
 
class Window_Main_Menu < Window_Base
  def initialize
    super(0 ,0 ,0 ,0)
    @sprite1 = Sprite.new
    @sprite1.bitmap = Cache.system( TitleMenu::MAIN_IMAGE )
    @sprite1.x = ( 0 )
    @sprite1.y = ( 0 )
    @sprite1.z = 10
    @sprite1.opacity = 255
  end
end
 
class Scene_Main_Menu < Scene_Base
  def start
    super
    @main_menu_window = Window_Main_Menu.new
  end
  def update
    super
    @main_menu_window.update
    if Input.trigger?🙂C)
      SceneManager.goto(Scene_Map)
    end
  end
  def terminate
    super
    @main_menu_window.dispose
  end
end
 
 
 
 
and the image turns out fine but is isnt transparent as it should be. 

it shows up ok but i cant see my charecter under it.

it has a dark background.

any way to get rid of the black background?

View attachment 19537
@sprite1.opacity = 255


255 is fully opaque. Put it to about 120 or 150 or something and it'll be semi-transparent.
still the same 

puttiog it to 30just faded the box below but the black background stayed
What is it that you're writing? Is it the title screen, or the main menu? What are you trying to achieve by rewriting it?


You're basing it off Scene_Base and not Scene_MenuBase. Scene_MenuBase has a method called create_background that grabs an image of the game map as it currently is and displays it as the background. But if you're writing the title screen, there IS no game map to grab.
omg!!!!

i have been trying so hard and yet you noticed the obvios!!!!

thank you senpai!!!!!!
EDIT:
You can't do it if that's the title screen though. There won't be a map to get when you first load the game.
I want to know what is the difference of these things in aliasing:

alias reisvcgo create_game_objects unless method_defined?('reisvcgo')this is a script that Reijubv, an rmvx scripter does on his scripts. Then I notice gubid do this:

alias milena_create_game_object create_game_object unless $@so what are these exactly?

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/