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.

Quick question involving switches variables and doors

I want it so that when I pull a switch you have limited time to open a door.

Here's what I have so far:

The Switch

Normal move event command for switch moving
Control Variable sets 0005 crypt switch = 1
Control Timer Startup 10 sec

This triggers another event when crypt switch = 1

Event

Conditional Branch Timer 10 sec or more
Control Variable sets 0005 crypt switch = 0
else etc.

There is a door activated by player touch as long as switch = 1

Problem - it always opens as longs as you hit the switch first i.e. Crypt switch variable doesnt change from 1 to 0 when the timer reaches 10.


Thanks in advance :)

EDIT : Solved the problem. Is there any way to make the timer invisible?
 

khmp

Sponsor

I apologize ahead of time for not having a non-script answer. :down:

I present you with two options. The top one hides the timer permanently. The bottom toggles on and off depending on a switch inside Game_System. The choice is yours depending on your tastes. In both cases though open up your script editor(F11) and insert an empty code section above "Main". Copy the code from the desired section below and paste it into the empty section you just created.

Code:
#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
#  This sprite is used to display the timer.It observes the $game_system
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Timer < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize ; end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose ; end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update ; end
end
The above code overrides every method in the sprite timer so it doesn't do anything. It effectively prevents the timer from ever being shown without messing with any other code.

You can also try this one below which shows the timer only if $game_system.timer_visible is true. You can use the "Script.." event command to change it at any time. By default the timer is always shown.
Code:
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of 
#  this class.
#==============================================================================

class Game_System
  alias_method :joby_hidingtimer_game_system_initialize, :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :timer_visible
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    joby_hidingtimer_game_system_initialize
    @timer_visible = true
  end
end

#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
#  This sprite is used to display the timer.It observes the $game_system
#  class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Timer < Sprite
  #--------------------------------------------------------------------------
  # * Frame Update !OVERRIDE!
  #--------------------------------------------------------------------------
  def update
    super
    # Set timer to visible if working
    self.visible = $game_system.timer_visible if $game_system.timer_working
    # If timer needs to be redrawn
    if $game_system.timer / Graphics.frame_rate != @total_sec
      # Clear window contents
      self.bitmap.clear
      # Calculate total number of seconds
      @total_sec = $game_system.timer / Graphics.frame_rate
      # Make a string for displaying the timer
      min = @total_sec / 60
      sec = @total_sec % 60
      text = sprintf("%02d:%02d", min, sec)
      # Draw timer
      self.bitmap.font.color.set(255, 255, 255)
      self.bitmap.draw_text(self.bitmap.rect, text, 1)
    end
  end
end

Using the "Script.." event command use either one of the lines below depending on what result you want.
Code:
$game_system.timer_visible = true # Show timer when applicable
$game_system.timer_visible = false # Hide timer when applicable

Good luck with it JonnyBoy! :thumb:
 
You know, the timer counts DOWN, not UP? You said in your Conditional Branch, that if it's 10 seconds or more, it'll reset the variable. But if that was a typo or you have a script to make it count up, check is the event with the Conditional Branch on Parallel Processing?

EDIT: Ehh never saw your edit at the bottom. Ignore this  :tongue:
 
@Regimos : Yeah, that was the problem!

@khmp : Gulp, thanks :) My first foray into scripting shall begin this evening then :) You said to just open up the script editor and paste this code in right? How do I get it to actually run the script?
 

khmp

Sponsor

Which one did you pick? If it's the first one you only need to have the code in your project in a section above main but below the rest. You don't need to run the script just the game as would normally. The second is a similar case but if you want the timer to not be seen use an event with the "Script.." event command and use this line:
Code:
$game_system.timer_visible = false
And that will hide the timer.

Good luck with it JonnnyBoy! :thumb:
 

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