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.

Waiting for X time (This time is a Request)

Status
Not open for further replies.
I don't Know Why I dont think before give the Last thread like Filled, but I'm very idiot or stupid, you choose.

Well, K.Seph Make me a little piece of code, and I Wonder in my mind, if it possible to change the Self switch by a Variable.

Let me explain, well, This script make when a X time is pass a Self switch is activated, now, I want when X time pass a Variable Operation occurs/happen. for example adition, substraction, (it's the principal, I dont want things like Multiplication, Percent or something like that, but if you can i dont will angry for that eh.  ::)).

this is the piece of code or script, I think is a script:

Code:
class Game_System
  attr_accessor :self_switch_timers
  alias_method :seph_selfswitchtimers_gmsys_init, :initialize
  def initialize
    @self_switch_timers = {}
    seph_selfswitchtimers_gmsys_init
  end
end

class << Graphics
  alias_method :seph_selfswitchtimers_graphics_update, :update
  def update
    seph_selfswitchtimers_graphics_update
    return if $game_system.nil?
    $game_system.self_switch_timers.each do |key, timestate|
      timestate[0] -= 1
      if timestate[0] < 0
        $game_self_switches[key] = timestate[1]
        $game_map.need_refresh = true
        $game_system.self_switch_timers.delete(key)
      end
    end
  end
end

Resume: I want transform this script, instead activate a Self Switch, change the variable value (with set, sums and substractions opt: Multiplication, division, and percents). withouth altering the structure of the script eh.
___

I wait, this request can be understanding.
__
 
You can always count on me. ;)

Code:
class Game_System
  class TimerOperations
    attr_accessor :switches
    attr_accessor :variables
    attr_accessor :self_switches
    def initialize
      @switches = {}
      @variables = {}
      @self_switches = {}
    end
    def update
      @switches.each do |switch_id, timervalue|
        timervalue[0] -= 1
        if timervalue[0] < 0
          $game_switches[switch_id] = timervalue[1]
          @switches.delete(switch_id)
          $game_map.need_refresh = true
        end
      end
      @variables.each do |variable_id, tov|
        tov[0] -= 1
        if tov[0] < 0
          $game_variables[variable_id].send(tov[1], tov[2])
          @variables.delete(variable_id)
          $game_map.need_refresh = true
        end
      end
      @self_switches.each do |key, timervalue|
        timervalue[0] -= 1
        if timervalue[0] < 0
          $game_self_switches[key] = timervalue[1]
          @self_switches.delete(key)
          $game_map.need_refresh = true
        end
      end
    end
  end
  attr_readers :timer_ops
  alias_method :seph_timeroperations_gmsys_init, :initialize
  def initialize
    @timer_ops = Game_System::TimerOperations.new
    seph_timeroperations_gmsys_init
  end
end

class << Graphics
  alias_method :seph_selfswitchtimers_graphics_update, :update
  def update
    seph_selfswitchtimers_graphics_update
    $game_system.timer_ops.update unless $game_system.nil?
  end
end


Ok. Now you adjust your switches like so:
Code:
$game_system.timer_ops.switches[switch_id] = [frames, bool]

Self-Switches:
Code:
$game_system.timer_ops.self_switches[[map_id, event_id, 'Letter']] = [frames, bool]

Variables is a bit more trickier.
Code:
$game_system.timer_ops.variables[variable_id] = [timer, operator, value]

Now, for operator, you need to have
:+=, :-=, :*=, :/= , or :%=

So if you wanted to add 5 to variable 4 in 350 frames
Code:
$game_system.timer_ops.variables[4] = [350, :+=, 5]

You must use a ':' + your operator
 
@PINEDAXP: What the hell does DerVV have to do with this thread?

Ok. Try this code out:
Code:
class Game_System
  class TimerOperations
    attr_accessor :switches
    attr_accessor :variables
    attr_accessor :self_switches
    def initialize
      @switches = {}
      @variables = {}
      @self_switches = {}
    end
    def update
      @switches.each do |switch_id, timervalue|
        timervalue[0] -= 1
        if timervalue[0] < 0
          $game_switches[switch_id] = timervalue[1]
          @switches.delete(switch_id)
          $game_map.need_refresh = true
        end
      end
      @variables.each do |variable_id, tov|
        tov[0] -= 1
        if tov[0] < 0
          case tov[1]
          when 0 ; $game_variables[variable_id] += tov[2]
          when 1 ; $game_variables[variable_id] -= tov[2]
          when 2 ; $game_variables[variable_id] *= tov[2]
          when 3 ; $game_variables[variable_id] /= tov[2]
          when 4 ; $game_variables[variable_id] %= tov[2]
          end
          @variables.delete(variable_id)
          $game_map.need_refresh = true
        end
      end
      @self_switches.each do |key, timervalue|
        timervalue[0] -= 1
        if timervalue[0] < 0
          $game_self_switches[key] = timervalue[1]
          @self_switches.delete(key)
          $game_map.need_refresh = true
        end
      end
    end
  end
  attr_reader :timer_ops
  alias_method :seph_timeroperations_gmsys_init, :initialize
  def initialize
    @timer_ops = Game_System::TimerOperations.new
    seph_timeroperations_gmsys_init
  end
end

class << Graphics
  alias_method :seph_selfswitchtimers_graphics_update, :update
  def update
    seph_selfswitchtimers_graphics_update
    $game_system.timer_ops.update unless $game_system.nil?
  end
endp/code]


Now instead of using :+=, use 0 - 4: 0 - Add, 1 - Subtract, 2 - Multiple, 3 - Divide, 4 - Modulus
 
Status
Not open for further replies.

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