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.

Variable At Coordinate

How would i use a script command to make a variable's number show up at a specified coordinate. Sorry if this is vague, but I don't really know how to elaborate further.
 

OS

Sponsor

Create a window (like the one below); place this above main and below all of the default scripts.

Code:
class Window_Text < Window_Base
  def initialize(x, y, var_id)
    super(x, y, 120, 64)
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    self.opacity = 0
    text = $game_variables[var_id].to_s
    self.contents.draw_text(0,-16,self.width,self.height,text)
  end
end

There are only two (known) problems with this so far: there are two arrows I can't remember how to get rid of, and you have to remember to dispose it when you want it off the screen.

In my test event, I used Call Script @window = Window_Text.new(0,0,2), then called Self Switch A, then created a new page for Call Script @window.dispose.

Each page was set to Action Button.

It works, but it doesn't look great yet (because of the arrows). I hope you can fix his little hiccup. Peace.
 
To get rid of the arrows, replace:
Code:
self.contents = Bitmap.new(self.width,self.height)

with:

Code:
self.contents = Bitmap.new(width - 32, height - 32)

Over and out - Gando
 

OS

Sponsor

Oh, doi! Thanks for that. I completely forgot about it. I haven't made a Window in RGSS in a little while, been too busy with C# and the VRE.

Previous post updated.
 
To change the font, put this line right below "self.contents = Bitmap.new(self.width - 32, self.height - 32)":

Code:
self.contents.font.name = "Times New Roman"

and replace "Times New Roman" with the name of the font you wish to have.

I don't have time to help you out with your other questions, sry, but i'll help you out tomorrow if noone has answered your questions, (which someone probably has by tomorrow :P)

Over and out - Gando
 

OS

Sponsor

Replace the above code with this one:

Code:
class Window_Text < Window_Base
  def initialize(x, y, var_id)
    super(x, y, 120, 64)
    self.contents = Bitmap.new(self.width-32,self.height-32)
    self.opacity = 0
    @var_id = var_id
    @state = $game_variables[@var_id]
    self.contents.draw_text(0,-16,self.width,self.height,@state.to_s)
  end
  
  def update
    if @state != $game_variables[@var_id].to_s
      if self.contents != nil
        self.contents.clear
      end
      @state = $game_variables[@var_id]
      self.contents = Bitmap.new(self.width-32,self.height-32)
      self.contents.draw_text(0,-16,self.width,self.height,@state.to_s)
    end
  end
end

class Game_System
  alias initlz_os_wind_text initialize
  alias update_os_wind_text update
  
  def initialize
    @text_windows = []
    initlz_os_wind_text
  end
  
  def update
    i = 0
    if @text_windows.length > 0
      while i < @text_windows.length
        @text_windows[i].update
        i += 1
      end
    end
    update_os_wind_text
  end
  
  def new_window(x, y, var_id)
    @text_windows.push(Window_Text.new(x,y,var_id))
  end
  
  def dispose_a_window(index)
    @text_windows[index].dispose
    @text_windows.delete_at(index)
  end
  
  def dispose_all_windows
    i = @text_windows.length - 1
    while i >= 0
      @text_windows[0].dispose
      @text_windows.delete_at(0)
      i -= 1
    end
  end
end

When you want to Create a window, use

$game_system.new_window(x,y,variable_id)

When you want to dispose of any particular window, use

$game_system.dispose_a_window(index), where index is the numerical index of the window in the array. The first window is 0, the second window is 1, the third window is 2, etc.

When you want to kill all of the windows, use

$game_system.dispose_all_windows

Remember, when you dispose of a single window, all the other windows after the one you dispose will drop to the next lowest index, so killing the window at index 1 will make the window with an index of 2 become 1, and the window at 3 become 2, and so on.

I hope this is what you want, and that I made sense. Peace!

~Owesome Scriptor
 

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