RPG Maker Forums

Salutations!


To begin with I am just a novice at coding, but have been diligently working on it. Please try to use simple terms.
I need assistance with a bit of coding that is most likely quite simple to fix, but I just can't figure it out after days of searching so I will post what I have and any and all assistance with it would be great.

RPG Maker VX Ace.

What I am trying to do:

  • Create an image that changes based on an in game variable


  def draw_image
    if $game_variables[15] = 1
      bitmap = Bitmap.new("Graphics/Faces/Image0")
      self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
    elsif $game_variables[15] = 1
      bitmap = Bitmap.new("Graphics/Faces/Image1")
      self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
    elsif $game_variables[15] = 2
      bitmap = Bitmap.new("Graphics/Faces/Image2")
      self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
    end
  end



This is the bit of code I have come up with. What happens for me is it draws the image I want if the var = 0, but even upon changing var[15] it stays the same image (even after refresh)

I already have a window which it places itself in fine, disappears when the window does and overall functions exactly as I'd like EXCEPT the image changing depending on a $game_variables[]


If this is in the wrong topic, or more information is needed, please let me know!


Thank you in advance for the help! 


EDIT:

After trying numerous code for the last several months (
Though only days after I posted this), I have made a solution!

#=====================================================================


# Module Piece to edit


#=====================================================================


module Hud_Config


# Picture = "Graphics/Pictures/test.jpg"


  PICTURE = {


    0 => "test0.jpg",


    1 => "test1.jpg",


    2 => "test3.jpg",


    }


# Variable to use to determine the picture to display


  VAR = 1


end


#=====================================================================


# Create the window


#=====================================================================


class Window_Hud < Window_Base


  def initialize


    super(0,0,250,75)


    update_padding


    update_tone


    create_contents


    refresh


  end


  def refresh


    self.contents.clear


    contents.clear


    draw_image


  def draw_image
      bitmap = Cache.picture(Hud_config::pICTURE[$game_variables[VAR]])
      self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
  end


end


#=====================================================================


# Scene to keep the HUD on the map


#=====================================================================


class Scene_Map < Scene_Base
  alias start_window start
  alias term_window terminate
  alias update_window update
  
  def start
    start_window
    @winhud = Window_Hud.new
    update
  end
  
  def terminate
    @winhud.dispose
    term_window
  end
  
  def update
    update_window
    @winhud.update
  end
end



I have more code in this for myself, but this is the basics of what I needed to be able to make a window that displayed an image based on a variable. You could probably add more arrays/variables to be able to use it for more than one instance as well, however I only need it for this.

Feel free to use this piece of code and edit it freely for commercial and non-commercial use. If you wanna share it, I'd just appreciate some credit.

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top