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.

How do i check if a method in a script is currently active?

Heya guys, in my game i set up a parallel process event. In that event i want to set up a conditional script check to see if a certain section of code in a script is currently running. How would i go about doing that?

Let me give you an example. On the top right of my screen i have a gui which displays my characters health, mana, and some other stats. Now i want that gui to remain on the screen at all times unless the screen is scrolling whether it's through the hero moving or just anytime the $game_map scroll method is active. How would i set up some sort of flag or switch in the method where i can do a conditional check in a parallel process event or other type of event to check if $game_map.scroll is currently active?
 
The simplest way is to not even do anything in an event, but rather adjust your windows visibility depending on if you are scrolling. Add this method before the final end in Game_Map
Code:
  def scrolling?
    return @scroll_rest > 0
  end

Now, which code is showing your GUI? You just need to add this in the update method:
Code:
self.visible = $game_map.scrolling == false
 
Ok You can add this:

Code:
class Game_Picture
  GUI_Pictures = [1, 2]
  alias_method :seph_guipictures_gmpict_update, :update
  def update
    seph_guipictures_gmpict_update
    if $game_map.scrolling?
      self.visible = false if GUI_Pictures.include?(@picture.number)
    end
  end
end

class Game_Map
  def scrolling?
    return @scroll_rest > 0
  end
end

Ok. Try that code and let me know if it works.
 
Ok. This should do the trick.

Code:
class Sprite_Picture
  GUI_Pictures = [1, 2]
  alias_method :seph_guipictures_sppict_update, :update
  def update
    seph_guipictures_sppict_update
    if $game_map.scrolling?
      self.visible = false if GUI_Pictures.include?(@picture.number)
    end
  end
end

class Game_Map
  def scrolling?
    return @scroll_rest > 0 || @player_scroll
  end
  alias_method :seph_guipicture_gmmap_sd, :scroll_down
  alias_method :seph_guipicture_gmmap_sl, :scroll_left
  alias_method :seph_guipicture_gmmap_sr, :scroll_right
  alias_method :seph_guipicture_gmmap_su, :scroll_up
  alias_method :seph_guipicture_gmmap_ud, :update
  def scroll_down(distance)
    last = @display_y
    seph_guipicture_gmmap_sd(distance)
    @player_scroll = true if last != @display_y
  end
  def scroll_left(distance)
    last = @display_x
    seph_guipicture_gmmap_sl(distance)
    @player_scroll = true if last != @display_x
  end
  def scroll_right(distance)
    last = @display_x
    seph_guipicture_gmmap_sr(distance)
    @player_scroll = true if last != @display_x
  end
  def scroll_up(distance)
    last = @display_y
    seph_guipicture_gmmap_su(distance)
    @player_scroll = true if last != @display_y
  end
  def update
    seph_guipicture_gmmap_ud
    @player_scroll = false
  end
end

A little more complicated then I thought. :s
 
Thanks seph, that did the trick but i do have a question. In that particular example it hides the two pictures while scrolling. How would i make it hide an entire viewport? In other words Let's say im using those two pics as part of the gui, but the other part of the gui is actual text that is written to the screen within those pictures. Would there be a way to also hide any text or anything else printed to the screen in that same area? If it's too much trouble don't even worry about it. This was just a side feature i thought about adding to my game. Not a big deal. :)
 
I made this awhile back:
Code:
#==============================================================================
# ** Mapping Layers
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2.1
# 2007-07-25
# SDK : Version 2.0+, Parts I & II
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- ()
#   Version 2 ---------------------------------------------------- (2007-04-03)
#    - Update : Rescripted entire system.
#    Version 2.1 ------------------------------------------------- (2007-07-25)
#     - Update : Updated code. Added script calls.
#------------------------------------------------------------------------------
# * Requirements :
#
#   Method & Class Library 2.1+ (When Using Keyboard Buttons)
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed as a debugging tool or just for fun. It allows
#   you to turn off "map layers" with the press of a button or script call. 
#   You may customize any Input or Keyboard button, and assign it to any of 
#   the following layer types :
#
#     'viewport1'   'viewport2'   'viewport3'
#     'layer1'      'layer2'      'layer3'
#     'fog'         'panorama'    'weather'
#     'tilemap'     'sprites'     'pictures'   'timer' 
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Customization :
#
#   Customizing Input keys that toggle layers or objects
#    - Input_Toggles[<object>] = <Input::Constant>
#
#   Customizing Keyboard keys that toggle layers or objects
#    - Keyboard_Toggles[<object>] = <Keyboard::Constant>
#
#   See Description for layer or object list. See * Toggle Buttons for further
#   instructions.
#------------------------------------------------------------------------------
# * Syntax :
#
#   Setting /Reading Spriteset and Tilemap to Mapping Layers Module
#    - Mapping_Layers.spriteset = spriteset object
#    - Mapping_Layers.tilemap   = tilemap object
#
#   Toggling Layers
#    - Mapping_Layers.toggle_spriteset_object(<object>)
#    - Mapping_Layers.toggle_tilemap_object(<object>)
#
#    'layer1', 'layer2' and 'layer3' require the toggle tilemap method.
#    All other objects use toggle spriteset object method.
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Mapping Layers', 'SephirothSpawn', 2.1, '2007-07-25')
SDK.check_requirements(2.0, [2]) 

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Mapping Layers')

#==============================================================================
# ** Mapping_Layers
#==============================================================================

module Mapping_Layers
  #--------------------------------------------------------------------------
  # * Toggle Buttons
  #
  #   Input Toggles (Uses Default Input Module)
  #    - Input_Toggles = { 'layername' => Input::Constant, ... }
  #
  #   Keyboard Toggles (Uses Keyboard Module)
  #    - Keyboard_Toggles = 'layername' => Keyboard::Constant, ... }
  #
  # * Input Button List
  #
  #   DOWN, LEFT, RIGHT, UP, SHIFT, CTRL, ALT, 
  #   A, B, C, X, Y, Z, L, R, F5, F6, F7, F8, F9
  #
  # * Keyboard Button List
  #
  #   (See Keyboard Module Constant List)
  #
  # * Layer Names List
  #
  #   'viewport1'   'viewport2'   'viewport3'
  #   'layer1'      'layer2'      'layer3'
  #   'fog'         'panorama'    'weather'
  #   'tilemap'     'sprites'     'pictures'   'timer' 
  #--------------------------------------------------------------------------
  Input_Toggles           = {}
  Input_Toggles['layer1'] = Input::F5
  Input_Toggles['layer2'] = Input::F6
  Input_Toggles['layer3'] = Input::F7
  Keyboard_Toggles        = {}
  #--------------------------------------------------------------------------
  # * Read Spriteset
  #--------------------------------------------------------------------------
  def self.spriteset
    return @spriteset
  end
  #--------------------------------------------------------------------------
  # * Write Spriteset
  #--------------------------------------------------------------------------
  def self.spriteset=(spriteset)
    @spriteset = spriteset
  end
  #--------------------------------------------------------------------------
  # * Read Tilemap
  #--------------------------------------------------------------------------
  def self.tilemap
    return @tilemap
  end
  #--------------------------------------------------------------------------
  # * Write Tilemap
  #--------------------------------------------------------------------------
  def self.tilemap=(tilemap)
    @tilemap = tilemap
  end
  #--------------------------------------------------------------------------
  # * Toggle Spriteset Object
  #--------------------------------------------------------------------------
  def self.toggle_spriteset_object(key, ss = @spriteset)
    # Return if Nil Spriteset
    return if ss.nil?
    # Keys List
    ks = %w(viewport1 viewport2 viewport3 fog panorama weather tilemap timer)
    # Instance Variables
    instances = [ss.viewport1, ss.viewport2, ss.viewport3, ss.fog, 
      ss.panorama, ss.weather, ss.tilemap, ss.timer_sprite]
    # If Key is 'Sprites'
    if key.downcase == 'sprites'
      # Update all Sprites in List
      ss.character_sprites.each { |s| s.visible = !s.visible }
    # If Key is 'Sprites'
    elsif key.downcase == 'pictures'
      # Update all Sprites in List
      ss.picture_sprites.each { |s| s.visible = !s.visible }
    elsif ks.include?(key.downcase)
      # Gets Index
      index = ks.index(key)
      # Change Visibleness
      instances[index].visible = !instances[index].visible
    end
  end
  #--------------------------------------------------------------------------
  # * Toggle Tilemap Object
  #--------------------------------------------------------------------------
  def self.toggle_tilemap_object(key, tm = @tilemap)
    # Return if Nil Tilemap
    return if tm.nil?
    # Gets Layer Keys
    keys = %w(layer1 layer2 layer3)
    # Return if not layer
    return unless keys.include?(key.downcase)
    # Create Map Data If Nil Map Data
    @map_data = {} if @map_data.nil?
    # Gets Z layer
    z = keys.index(layer)
    # If Layer Already Created
    if @map_data.has_key?(z) && @map_data[z] != nil
      # Pass Through Tilemap X
      for x in 0...tm.map_data.xsize
        # Pass Through Tilemap Y
        for y in 0...tm.map_data.ysize
          # Restore Map Data
          tm.map_data[x, y, z] = @map_data[z][x, y]
        end
      end
      # Clear Map Layer Data
      @map_data[z] = nil
    # If Layer Not Created
    else
      # Create Layer Data
      @map_data[z] = Table.new(tm.map_data.xsize, 
                               tm.map_data.ysize)
      # Pass Through Tilemap X
      for x in 0...tm.map_data.xsize
        # Pass Through Tilemap Y
        for y in 0...tm.map_data.ysize
          # Store Map Data
          @map_data[z][x, y] = tm.map_data[x, y, z]
          # Clear Map Data
          tm.map_data[x, y, z] = 0
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def self.ss_update(ss = @spriteset)
    # Keys List
    ks = %w(viewport1 viewport2 viewport3 fog panorama weather tilemap timer)
    # Instance Variables
    instances = [ss.viewport1, ss.viewport2, ss.viewport3, ss.fog, 
      ss.panorama, ss.weather, ss.tilemap, ss.timer_sprite]
    # Pass Through Input Buttons
    Input_Toggles.each do |key, button|
      # If Button Pressed
      if Input.trigger?(button)
        # If Key is 'Sprites'
        if key == 'sprites'
          # Update all Sprites in List
          ss.character_sprites.each { |s| s.visible = !s.visible }
        # If Key is 'Sprites'
        elsif key == 'pictures'
          # Update all Sprites in List
          ss.picture_sprites.each { |s| s.visible = !s.visible }
        elsif ks.include?(key)
          # Gets Index
          index = ks.index(key)
          # Change Visibleness
          instances[index].visible = !instances[index].visible
        end
      end
    end
    # If Keyboard Module Enabled
    if SDK.enabled?('Method & Class Library', 2.1)
      # Pass Through Keyboard Buttons
      Keyboard_Toggles.each do |key, button|
        # If Button Pressed
        if Keyboard.trigger?(button)
          # If Key is 'Sprites'
          if key == 'sprites'
            # Update all Sprites in List
            ss.character_sprites.each { |s| s.visible = !s.visible }
          # If Key is 'Sprites'
          elsif key == 'pictures'
            # Update all Sprites in List
            ss.picture_sprites.each { |s| s.visible = !s.visible }
          elsif ks.include?(key)
            # Gets Index
            index = ks.index(key)
            # Change Visibleness
            instances[index].visible = !instances[index].visible
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Tilemap Layers
  #--------------------------------------------------------------------------
  def self.tml_update(tilemap = @spriteset.tilemap)
    # Gets Layer Keys
    keys = %w(layer1 layer2 layer3)
    # Pass Through Each Layer
    keys.each do |layer|
      # Turn Off Switch Layer
      switch_layer = false
      # If Input Key Defined
      if Input_Toggles.has_key?(layer)
        # If Key Pressed
        if Input.trigger?(Input_Toggles[layer])
          # Turn On Switch Layer
          switch_layer = true
        end
      end
      # If Keyboard Module Enabled
      if SDK.enabled?('Method & Class Library', 2.1)
        # If Keyboard Key Defined
        if Keyboard_Toggles.has_key?(layer)
          # If Key Pressed
          if Keyboard.trigger?(Keyboard_Toggles[layer])
            # Turn On Switch Layer
            switch_layer = true
          end
        end
      end
      # If Switch Layer
      if switch_layer
        # Create Map Data If Nil Map Data
        @map_data = {} if @map_data.nil?
        # Gets Z layer
        z = keys.index(layer)
        # If Layer Already Created
        if @map_data.has_key?(z) && @map_data[z] != nil
          # Pass Through Tilemap X
          for x in 0...tilemap.map_data.xsize
            # Pass Through Tilemap Y
            for y in 0...tilemap.map_data.ysize
              # Restore Map Data
              tilemap.map_data[x, y, z] = @map_data[z][x, y]
            end
          end
          # Clear Map Layer Data
          @map_data[z] = nil
        # If Layer Not Created
        else
          # Create Layer Data
          @map_data[z] = Table.new(tilemap.map_data.xsize, 
                                   tilemap.map_data.ysize)
          # Pass Through Tilemap X
          for x in 0...tilemap.map_data.xsize
            # Pass Through Tilemap Y
            for y in 0...tilemap.map_data.ysize
              # Store Map Data
              @map_data[z][x, y] = tilemap.map_data[x, y, z]
              # Clear Map Data
              tilemap.map_data[x, y, z] = 0
            end
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Clear Map Data
  #--------------------------------------------------------------------------
  def self.clear_map_data
    @map_data = {}
  end
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :viewport1, :viewport2, :viewport3, :fog, :panorama, :weather
  attr_reader :tilemap, :character_sprites, :picture_sprites, :timer_sprite
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_mappinglayers_ssmap_init_tm, :init_tilemap
  alias_method :seph_mappinglayers_ssmap_update,  :update
  #--------------------------------------------------------------------------
  # * Object Initialization : Tilemap
  #--------------------------------------------------------------------------
  def init_tilemap
    # Original Initialization
    seph_mappinglayers_ssmap_init_tm
    # Clear Mapping Layers Map Data 
    Mapping_Layers.clear_map_data
    # Set Spriteset
    Mapping_Layers.spriteset = self
    # Set Tilemap
    Mapping_Layers.tilemap = @tilemap
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update Mapping Layers Module
    Mapping_Layers.ss_update
    # Update Tilemap Layers
    Mapping_Layers.tml_update
    # Original Update
    seph_mappinglayers_ssmap_update
  end
end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

So if you wanted to turn off a viewport:
Code:
Mapping_Layers.toggle_spriteset_object('viewport1')

Change the 1 in there to 2 or 3. That may not be what you want though. Could you explain exactly what you are turning on and off?

And with the script I already gave you, you can turn off multiple pictures:
Code:
GUI_Pictures = [1, 2]

Just add picture ids there.
 

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