Quick Assistance with draw_image and $game_variables

Genqar

Warper
Member
Joined
Oct 30, 2014
Messages
3
Reaction score
0
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
I've moved this thread to RGSSx Script Support . Please be sure to post your threads in the correct forum next time. Thank you.
 

Kilana

Warper
Member
Joined
Jul 2, 2016
Messages
4
Reaction score
0
First Language
English
Primarily Uses
I think the issue with the original code is using a single = symbol in the if lines.


X = 100    #Sets X to 100


X == 100  #Checks if X is 100

Code:
   def draw_image
    if $game_variables[15] == 0
      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
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
There are many issues with the "solution" script...

  1. You forgot to end the refresh method in your window class. You actually typed in the whole code here instead of copy/paste? o.o
  2. This line: 

    bitmap = Cache.picture(Hud_config::pICTURE[$game_variables[VAR]])


    Will give an error. It should be:


    bitmap = Cache.picture(Hud_config::pICTURE[$game_variables[Hud_config::VAR]])


  3. You don't have to call the update method on windows created in any scene which inherits from Scene_Base. They are updated automatically. If you call update on them, they will be updated twice in each frame.
  4. You don't have to call dispose on windows created in any scene which inherits from Scene_Base either. They are disposed automatically.

Not sure what this script does actually? With just the code you shared, the image shown will not be updated in real time, only when Scene_Map is re-started. If that was the function you wanted, than it works how you want it to work, but if you want real time image changes the moment you change the assigned variable, you will need to make a logical update method for it somewhere in the window's update method.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top