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.

deleting a string with draw_text command using switches

i'm using:-

self.contents.draw_text(200, 2, 320, 32, "test string")

basically that line appears when switch 28 is activated on a separate window.

how would i make that string disappear/delete when another different switch is activated?

Thanks.
 
If I understand your question correctly, use this:
Code:
if $game_switches[[color=red]i[/color]]
  # text when switch is on
elsif $game_switches[[color=red]i[/color]]
  # text when other switch is on
end

Replace "i" with the switch number.
 
Hi, thanks for reply

I tried that and it doesn't delete the first line of text (or even print the second line of text) when the second switch is activated

any other ideas?
 
yes i did.

I've just worked out another way of doing it, which works
but is going to be awkward when the player has loads of quests.

but thanks for your help

I've posted the code incase you wanted to look at it or use it.

Code:
#-------------------------------
#----Quests Window V.1----------
#-------------------------------

class Scene_Quests

#----def main-------------------
  def main
    @quests_status = Window_QuestsStatus.new
    @quests_window = Window_Quests.new
    @quests_status.opacity = 100
    @quests_window.opacity = 100
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @quests_status.dispose
    @quests_window.dispose
  end
  
#----def update-----------------
  def update
    @quests_window.update
    @quests_status.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
  end
end


#-------------------------------
#---------Window_Quests---------
#-------------------------------

class Window_Quests < Window_Selectable

#----def initialize-------------
  def initialize
    super(0, 60, 640, 420)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    refresh
  end
  
#----def refresh----------------
def refresh
  self.contents.font.color = normal_color
  self.contents.draw_text(505, 420, 120, 32, "Press Esc To Exit")
  
  # Quests listed here....
   if $game_switches[61] == true
  self.contents.draw_text(10, 2, 320, 32, "Rat Quest (Eagle Tavern)")
   end

  if $game_switches[62] == true and $game_switches [61] == false
  self.contents.draw_text(10, 2, 320, 32, "Camper Quest (Merriwynne North)")
elsif
  $game_switches[62] == true
  self.contents.draw_text(10, 32, 320, 32, "Camper Quest (Merriwynne North)")
  end

  if $game_switches[63] == true and $game_switches [61] == false and $game_switches [62] == false
  self.contents.draw_text(10, 2, 320, 32, "School Quest (Merriwynne S.E)")
  elsif
  $game_switches[63] == true and $game_switches [61] == true and $game_switches [62] == false
  self.contents.draw_text(10, 32, 320, 32, "School Quest (Merriwynne S.E)")
  elsif
  $game_switches[63] == true and $game_switches [61] == true and $game_switches [62] == true
  self.contents.draw_text(10, 62, 320, 32, "School Quest (Merriwynne S.E)")
  end
  
  

end
end

#-------------------------------
#----Window_QuestsStatus--------
#-------------------------------

class Window_QuestsStatus < Window_Base
  
  def initialize
    super(0, 0, 640, 60)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Tahoma"
    self.contents.font.size = 22
    refresh
  end
  
  def refresh
    self.contents.draw_text(10, 0, 320, 32, "Current Quests")
     end
end
 
In a situation like this where you need to change the contents of a window during it's updates, you should use self.contents.clear to clean the window. You then draw all the neccessary strings on. This prevents the same string from being drawn over and over again, which causes the transparent parts of the letter to build up and look ugly :-/

By the way, you do not need to use == true in Ruby. Any object that is not nil or false is evaluated as true. a == b is simply a method that examines a and b and checks if they are the same, returning either true or false:
Code:
a = 1
b = 1
print a == b [color=green]# returns true

# this:[/color]
x = true
y = false
if x == true and y == false
  print "x = true & y = false"
end
[color=green]# is the same as this:[/color]
if x and !y
  print "x = true & y = false"
end
In the example with x and y, x == true compares true to true. As they are they same, the method returns true. When both the == methods and the and method have all been run, you are left with either true or false. So when dealing with objects that are either true or false anyway, there is no need to compare them with ==. In the second example, x does not need to be evaluated so it is left as it is. The !y method takes y and reverses it:
Code:
p = true
print !p [color=green]# prints false[/color]

q = "Hello"
print !q [color=green]# prints false: "Hello" is evaluated as true, and then reversed to false[/color]
 

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