Ruby: Selecting object data from an iterated hash

3 1 1
                                    

There's a neat little snippet of code that I've been working on in Ruby for a code in RPG Maker VX Ace. (If you're interested, I was coding a TimeStop script, and I needed to collect object data from a hash to update sprite tone values to make them lose color when time stops :/)

Let's say you're using RGSS3 at the moment.

(Note, because the /at/ symbol doesn't work in Wattpad, I will use the IPA voiceless dental fricative (also the Greek theta) instead: example = θexample_instance_variable)

Look at this code:

'

class Sprite_Character < Sprite
attr_accessor  :character

  # character: Game_Character
  def initialize(character, viewport = nil)
    super(viewport) unless viewport.nil?
    θcharacter = character
    update
  end

  def update
    super
    update_bitmap_rect   # Yeah I'm not defining this here
    update_tone
  end

  # Here's where the selection stuff happens
  def update_tone
    tint = $game_screen.tone # This is a coloring method that preserves the screen's tint
   
self.tone = tint #Sets the tint of the sprite
    if $game_system.timestop? && θcharacter.timestopped? 
      # The below runs if the character that this sprite refers to is stopped by the time
      # stop function.  i.e, if the character needs to lose color.
      bwtint = Tone.new(0, 0, 0, 256)
      self.tone = bwtint # sets the tint of this sprite to grayscale
    else
      self.tone = tint  # Resets the tone to the screen tone if the character isn't timestopped (or b/w)
    end
  end

end

'

So complex

You've reached the end of published parts.

⏰ Last updated: Mar 22, 2021 ⏰

Add this story to your Library to get notified about new parts!

Programming TutorialsWhere stories live. Discover now