General RGSS/RGSS2/RGSS3 Help

Started by G_G, March 04, 2009, 12:14:28 am

Previous topic - Next topic

G_G

March 04, 2009, 12:14:28 am Last Edit: April 17, 2012, 09:16:01 am by game_guy
General RGSS/RGSS2 Help





Introduction

Here is a general RGSS/RGSS2/RGSS3 Help Topic. You're welcome to ask any question about either scripting language to help you be a scripter.


Instructions

First search the topic for your question.  It might have already been answered, so please search first.


Notes

If we don't answer right away, just wait a day or two then bump it.

Landith

Maybe have an if branch to see if the player is pressing left, right, up, or down then refresh the window to prevent lag? I would check out Ccoa's HUD tutorial on rpgrevolution, it has a solution to this. Don't have a link at the present time because I'm on my phone, I might be able to get one in a little bit though

Fantasist

How's your update method like? Could you post it?
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




G_G

Coordinate Window: ShowHide
class Window_Coordinate < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120, 32, "X: " + $game_player.x.to_s)
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, "Y: " + $game_player.y.to_s)
  end
end


Scene_Map: ShowHide
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make sprite set
    @coordinate = Window_Coordinate.new
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    @coordinate.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Loop
    loop do
      # Update map, interpreter, and player order
      # (this update order is important for when conditions are fulfilled
      # to run any event, and the player isn't provided the opportunity to
      # move in an instant)
      $game_map.update
      $game_system.map_interpreter.update
      @coordinate.update
      $game_player.update
     
      # Update system (timer), screen
      $game_system.update
      $game_screen.update
      # Abort loop if player isn't place moving
      unless $game_temp.player_transferring
        break
      end
      # Run place move
      transfer_player
      # Abort loop if transition processing
      if $game_temp.transition_processing
        break
      end
    end
    # Update sprite set
    @spriteset.update
    # Update message window
    @message_window.update
    # If game over
    if $game_temp.gameover
      # Switch to game over screen
      $scene = Scene_Gameover.new
      return
    end
    # If returning to title screen
    if $game_temp.to_title
      # Change to title screen
      $scene = Scene_Title.new
      return
    end
    # If transition processing
    if $game_temp.transition_processing
      # Clear transition processing flag
      $game_temp.transition_processing = false
      # Execute transition
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    # If showing message window
    if $game_temp.message_window_showing
      return
    end
    # If encounter list isn't empty, and encounter count is 0
    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      # If event is running or encounter is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        # Confirm troop
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        # If troop is valid
        if $data_troops[troop_id] != nil
          # Set battle calling flag
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end
    # If debug mode is ON and F9 key was pressed
    if $DEBUG and Input.press?(Input::F9)
      # Set debug calling flag
      $game_temp.debug_calling = true
    end
    # If player is not moving
    unless $game_player.moving?
      # Run calling of each screen
      if $game_temp.battle_calling
        call_battle
      elsif $game_temp.shop_calling
        call_shop
      elsif $game_temp.name_calling
        call_name
      elsif $game_temp.menu_calling
        call_menu
      elsif $game_temp.save_calling
        call_save
      elsif $game_temp.debug_calling
        call_debug
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Battle Call
  #--------------------------------------------------------------------------
  def call_battle
    # Clear battle calling flag
    $game_temp.battle_calling = false
    # Clear menu calling flag
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    # Make encounter count
    $game_player.make_encounter_count
    # Memorize map BGM and stop BGM
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
    $game_system.bgm_play($game_system.battle_bgm)
    # Straighten player position
    $game_player.straighten
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
  #--------------------------------------------------------------------------
  # * Shop Call
  #--------------------------------------------------------------------------
  def call_shop
    # Clear shop call flag
    $game_temp.shop_calling = false
    # Straighten player position
    $game_player.straighten
    # Switch to shop screen
    $scene = Scene_Shop.new
  end
  #--------------------------------------------------------------------------
  # * Name Input Call
  #--------------------------------------------------------------------------
  def call_name
    # Clear name input call flag
    $game_temp.name_calling = false
    # Straighten player position
    $game_player.straighten
    # Switch to name input screen
    $scene = Scene_Name.new
  end
  #--------------------------------------------------------------------------
  # * Menu Call
  #--------------------------------------------------------------------------
  def call_menu
    # Clear menu call flag
    $game_temp.menu_calling = false
    # If menu beep flag is set
    if $game_temp.menu_beep
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Clear menu beep flag
      $game_temp.menu_beep = false
    end
    # Straighten player position
    $game_player.straighten
    # Switch to menu screen
    $scene = Scene_Menu.new
  end
  #--------------------------------------------------------------------------
  # * Save Call
  #--------------------------------------------------------------------------
  def call_save
    # Straighten player position
    $game_player.straighten
    # Switch to save screen
    $scene = Scene_Save.new
  end
  #--------------------------------------------------------------------------
  # * Debug Call
  #--------------------------------------------------------------------------
  def call_debug
    # Clear debug call flag
    $game_temp.debug_calling = false
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Straighten player position
    $game_player.straighten
    # Switch to debug screen
    $scene = Scene_Debug.new
  end
  #--------------------------------------------------------------------------
  # * Player Place Move
  #--------------------------------------------------------------------------
  def transfer_player
    # Clear player place move call flag
    $game_temp.player_transferring = false
    # If move destination is different than current map
    if $game_map.map_id != $game_temp.player_new_map_id
      # Set up a new map
      $game_map.setup($game_temp.player_new_map_id)
    end
    # Set up player position
    $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
    # Set player direction
    case $game_temp.player_new_direction
    when 2  # down
      $game_player.turn_down
    when 4  # left
      $game_player.turn_left
    when 6  # right
      $game_player.turn_right
    when 8  # up
      $game_player.turn_up
    end
    # Straighten player position
    $game_player.straighten
    # Update map (run parallel process event)
    $game_map.update
    # Remake sprite set
    @spriteset.dispose
    @spriteset = Spriteset_Map.new
    # If processing transition
    if $game_temp.transition_processing
      # Clear transition processing flag
      $game_temp.transition_processing = false
      # Execute transition
      Graphics.transition(20)
    end
    # Run automatic change for BGM and BGS set on the map
    $game_map.autoplay
    # Frame reset
    Graphics.frame_reset
    # Update input information
    Input.update
  end
end

Fantasist

OK. In Scene_Map#update, here's how you're updating the coordinate window:

if @coordinate.visible == true
      update_coordinate
    end


But update_coordinate is not defined. Besides, if you want to update the coordinate window, you should use:


@coordinate.update


That will call the update method in Window_Coordinate IF that method is defined in Window_Coordinate, which is not. You only defined initialize and refresh. Make an update method and check if the player's X and Y coordinates have changed. If they have, call refresh. Do all of this in Window_Coordinate#update. Then all you have to do in Scene_Map#update is:


if @coordinate.visible == true
  @coordinate.update
end
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

    if @coordinate.visible
      update_coordinate
    end


Optimized. :P
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Ha. Both of ya is wrong.


@coordinate.update if @coordinate.visible

Blizzard

HAHA! YOU FELL RIGHT INTO MY TRAP!


@coordinate.update if @coordinate.visible && @coordinate.active


Also, it being in one line instead of 3 doesn't change the performance.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

It still doesnt work. I used
@coordinate.update if @coordinate.visible && @coordinate.active

And still no luck. Also I added this under @coordinate = Window_Coordinate.new

def initialize
  @coordinate = Window_Coordinate.new
  @coordiante.visible = true
  @coordinate.active = true
end


Still no luck. Its not updating at all.

Tazero



If you were a fish...

fugibo

Yes; one ampersand is a bitwise operator. Two ampersands is the same as using the keyword "and," but since there is a bug with that that Blizz found a year or two ago, we always use "&&" here if possible.

G_G

March 04, 2009, 06:41:18 pm #11 Last Edit: March 04, 2009, 07:30:14 pm by game_guy
Okay I realized that I totally forgot something. In Window_Coordinate I didn't add a def update in it so it wasnt really updating the window. So its all figured out and done!!! Still need to know this

One more question is it possible to display a picture in the window? Like normally i've been using
RPG::Cache.picture("")
But that displays a picture in the whole scene and I just want it in a window if possible.


fugibo


G_G

What? I'm not having problems display pictures.

I want to display a picture in the window without having to set x and y coordinates and RPG::Cache.picture("")
Like is there a line of code I can add in a window that displays a picture in the window?

winkio

you are confusing people because you have no idea what you are talking about.

RPG::Cache.picture("filename.png") get the image of the filename.

Then, you have to either set it to a background or display it some other way.

HOW do you want it in the window?  As a background?  or just inside its bounds?  either way, it should be pretty obvious...

fugibo

I think you'd need this:

window.contents = Bitmap.new(path_to_file)


OR


window.contents = RPG::Cache.<pick_ur_method>(filename)

G_G

March 04, 2009, 10:49:37 pm #16 Last Edit: March 04, 2009, 10:52:09 pm by game_guy
Thanks WcW yea I had no idea what I was talking about. I had it prefectly said right in my head but hey we all think differently right?

EDIT: Wait I tried both methods, then it jsut displays the picture for like half a second then dissappears, then it shows two arrows, one pointing down, and one points right.

fugibo

Oh, you probably don't have the window's size set right :P

Another method that you might want to use is


src = Rect.new(0, 0, <width>, <height>)
dst = Rect.new(<ur x>, <ur y>, <width>, <height>)
window.contents.blt(src, Bitmap.new(<filename>), dst) # takes the image at <src> from the bitmap and draws it at <dst>


Or something like that; it's in the help file, under Bitmap.

G_G

New question:

How would you go making a Horizontal command window for a menu? Instead of a normal command window one that has the selections side by side: Items, Skills, etc. Could someone tell me or guide me on my way or something.

If you need to contact me, my msn is gameguy27@hotmail.com

G_G