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.

Compass Script

I'm working on a project that involves changing perspectives on numerous occasions. For example, you exit one map to the top of the screen (north) and come out on the next map from the right side of the screen, thus making the left side of the screen the 'north' direction. An early puzzle to earn the compass is a disorientation puzzle, but after you obtain the puzzle, an icon appears in the upper left corner that changes to show which direction is which.

The script is extremely basic. I just need a switch that turns 'compass display' on and off (so that I can turn it off in cutscenes), and a command to change the image. IE, read the 'compassN.png' image if I'm facing north, read 'compassE.png' if facing east, etc.

I'd appreciate any help I can get with this.:D
 
In your Scene add in main:
Code:
@compass = Sprite.new
@compass_switch = 99
and in your update method add:
Code:
update_compass
and last put this one in your scene.
Code:
def update_compass
  if ($game_swithes[@compass_switch] == true)
    @compass.visible = true
  else
    @compass.visible = false
  end
  if @temp_direction != $game_player.direction
    @temp_direction = $game_player.direction
    case $game_player.direction
    when 2 # Down
      bitmap = "compassN"
    when 4 # Left
      bitmap = "compassW"
    when 6 # Right
      bitmap = "compassE"
   when 8 # UP
      bitmap = "compassS"
    end
    @compass.bitmap = RPG::Cache.picture(bitmap)
    @compass.update
  end
end
 
Er, I may be misunderstanding (I'm not good at RGSS) but what I wanted was a compass that changed when I changed maps through a manual command, not one that changed every time the player changed directions.
 
ScriptKitty;205984 said:
Er, I may be misunderstanding (I'm not good at RGSS) but what I wanted was a compass that changed when I changed maps through a manual command, not one that changed every time the player changed directions.

Oops, sorry I misunderstood.
underneath
Code:
@compass_switch = 99
add
Code:
@compass_variable = 99
And replace this method with the one above ^_^
Code:
def update_compass
  if ($game_swithes[@compass_switch] == true)
    @compass.visible = true
  else
    @compass.visible = false
  end
  case $game_variables[@compass_variable]
  when 2 # Down
    bitmap = "compassN"
  when 4 # Left
    bitmap = "compassW"
  when 6 # Right
    bitmap = "compassE"
  when 8 # UP
    bitmap = "compassS"
  end
  @compass.bitmap = RPG::Cache.picture(bitmap)
  @compass.update
end
To change direction
North: $game_variable[99] = 8
East: $game_variable[99] = 6
South: $game_variable[99] = 2
West: $game_variable[99] = 4
 
Thank you very much! Though I'm still a little fuzzy on just where I'm supposed to put these tidbits of code. Exactly what files are these supposed to go into? Scene_Map? Where exactly in Scene_Map do they go?


...if you really felt like doing me a giant favor, this is my Scene_Map file if you feel like updating it for me is easier than telling me how @_@ :

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

class Scene_Map
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make sprite set
    @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
    # 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 do

      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update

      $game_system.update
      $game_screen.update

      unless $game_temp.player_transferring
        break
      end

      transfer_player

      if $game_temp.transition_processing
        break
      end
    end

    @spriteset.update
    @message_window.update

    if $game_temp.gameover
      $scene = Scene_Gameover.new
      return
    end

    if $game_temp.to_title
      $scene = Scene_Title.new
      return
    end

    if $game_temp.transition_processing
      $game_temp.transition_processing = false
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end

    if $game_temp.message_window_showing
      return
    end

    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        if $data_troops[troop_id] != nil
          $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 Input.trigger?(Input::B)
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end

    # Check if "Shift" was pressed and call the field item window
    if Input.trigger?(Input::SHIFT)
      @field_item = Field_Item.new
      @field_item.main
    end

    if $DEBUG and Input.press?(Input::F9)
      $game_temp.debug_calling = true
    end

    unless $game_player.moving?
      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


Again, thank you SO MUCH.
 
Here you go:
Code:
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias
  #--------------------------------------------------------------------------
  alias :freakboy_compass_scene_map_main :main
  alias :freakboy_compass_scene_map_update :update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create a Sprite Object
    @compass = Sprite.new
    # Switch to toggle visibility
    @compass_switch = 99
    # Set it to North on Startup
    @compass_variable = 8
    # Call the Aliased Method
    freakboy_compass_scene_map_main
    # Dispose the Sprite Object
    @compass.dispose if (not @compass.disposed?)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update the Compass
    update_compass
    # Call the Aliased Method
    freakboy_compass_scene_map_update
  end
  #--------------------------------------------------------------------------
  # * Compass Update
  #--------------------------------------------------------------------------
  def update_compass
    # If the Switch if ON
    if ($game_switches[@compass_switch] == true)
      # Compass is visible
      @compass.visible = true
    else
      # Else the Compass is invisible
      @compass.visible = false
    end
    # Get the direction
    case $game_variables[@compass_variable]
    when 2 # South
      bitmap = "compassS"
    when 4 # West
      bitmap = "compassW"
    when 6 # East
      bitmap = "compassE"
    when 8 # North
      bitmap = "compassN"
    else
      bitmap = "compassN"
    end
    @compass.bitmap = RPG::Cache.picture(bitmap)
    @compass.update
  end
end
I don't need credit for this ^_^

--edit--
fixed a little error :P
 
Aww. I just made this:
Code:
COMPASS_SHOW_SWITCH = 1

class Sprite_Compass < Sprite
  attr_writer :direction
  def initialize
    super()
    @direction = 'south'
    self.visible = $game_switches[COMPASS_SHOW_SWITCH]
    self.z = 9999999
    refresh
  end
  def refresh
    @old_dir = @direction
    if self.bitmap != nil
      self.bitmap.dispose
      self.bitmap = nil
    end
    self.bitmap = RPG::Cache.picture('compass_' + @direction)
  end
  def update
    super()
    self.visible = $game_switches[COMPASS_SHOW_SWITCH]
    refresh if @old_dir != @direction
  end
end
class Scene_Map
  alias_method :compass_main, :main
  alias_method :compass_update, :update
  def main
    @compass = Sprite_Compass.new
    compass_main
    @compass.dispose
  end
  def update
    compass_update
    @compass.update
  end
  def change_dir(direction)
    @compass.direction = direction.downcase
  end
end
You just install it and to change direction, just call $scene.change_dir(string) where string is 'north', 'south', 'west' or 'east'. You'll need four images in the picture directory called compass_north, compass_south, compass_west and compass_east.
 
Yeyinde;206008 said:
Aww. I just made this:
Code:
COMPAS_SHOW_SWITCH = 1

class Sprite_Compass < Sprite
  attr_writer :direction
  def initialize
    super()
    @direction = 'south'
    self.visible = $game_swtiches[COMPASS_SHOW_SIWTCH]
    self.z = 9999999
    refresh
  end
  def refresh
    @old_dir = @direction
    if self.bitmap != nil
      self.bitmap.dispose
      self.bitmap = nil
    end
    self.bitmap = RPG::Cache.picture('compass_' + @direction)
  end
  def update
    super()
    self.visible = $game_swtiches[COMPASS_SHOW_SIWTCH]
    refresh if @old_dir != @direction
  end
end
class Scene_Map
  alias_method :compass_main, :main
  alias_method :compass_update, :update
  def main
    @compass = Sprite_Compass.new
    compass_main
    @compass.dispose
  end
  def update
    compass_update
    @compass.update
  end
  def change_dir(direction)
    @compass.direction = direction.downcase
  end
end
You just install it and to change direction, just call $scene.change_dir(string) where string is 'north', 'south', 'west' or 'east'. You'll need four images in the picture directory called compass_north, compass_south, compass_west and compass_east.
Can I use it then? :P
 
With Yeyinde's script I get this error when the map loads:

Script '*Compass' line 8: NameError occurred.
uninitialized constant Sprite_Compass::COMPASS_SHOW_SIWTCH

Freakboy;206016 said:
Did you put my script below Scene_Map ?

I misunderstood, I thought yours was supposed to replace Scene_Map@_@


I'm RGSS illiterate, people.:'(
 

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