Help - Search - Members - Calendar
Full Version: Updating/Refreshing window
RPG RPG Revolution Forums > Scripting > Script Development and Support
Sir_Ver
Hi guys. I'm very new to scripting, and I'm having trouble trying to get my window to update and what not. I've done my best to learn, but I'm stuck. Could you please give me a small push in the right direction.

CODE
class Window_Betting < Window_Base
  
  #-----------------------------------------
  ######Object Initialization###############
  #-----------------------------------------
  attr_accessor   :variable
  def initialize
    super (0, 0, 256, 96)
        self.contents = Bitmap.new(width - 32, height - 32)
        #Wins and Losses
        @Betting_Wins=$game_variables[1]
        @Betting_GoldWon=$game_variables[2]
    
    refresh
end
  #-------------------------------------------
  #############Refresh########################
  #-------------------------------------------
  def refresh
    self.contents.clear
    update
    self.contents.draw_text(0, 0, 256, 32, "Dice Gamble", 1)
    self.contents.draw_text(0, 0, 256, 64, "Wins")
    self.contents.draw_text(0, 0, 256, 64, @Betting_Wins.to_s, 1)
    self.contents.draw_text(0, 0, 256, 98, "Gold Won")
    self.contents.draw_text(0, 0, 256, 98, @Betting_GoldWon.to_s,1)
    end

  #--------------------------------------------
  ##############Update#########################
  #--------------------------------------------
  def update
    super
    if $game_variables[1] != @Betting_Wins or $game_variables[2] != @Betting_GoldWon
      @Betting_Wins=$game_variables[1]
      @Betting_GoldWon=$game_variables[2]
      end  
  end
  end
Night_Runner
Hello Sir_Ver smile.gif

I just wanted to say, you have @B at the start of a lot of variable names, never start your variable names with capital letters.
Capitalised first letters are reserved for class names and constants.

And one more slight edit to your code:
CODE
class Window_Betting < Window_Base
  #-----------------------------------------
  ######Object Initialization###############
  #-----------------------------------------
  attr_accessor   :variable
  def initialize
    super (0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    #Wins and Losses
    @betting_Wins=$game_variables[1]
    @betting_GoldWon=$game_variables[2]
    refresh
end
  #-------------------------------------------
  #############Refresh########################
  #-------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 256, 32, "Dice Gamble", 1)
    self.contents.draw_text(0, 0, 256, 64, "Wins")
    self.contents.draw_text(0, 0, 256, 64, @betting_Wins.to_s, 1)
    self.contents.draw_text(0, 0, 256, 98, "Gold Won")
    self.contents.draw_text(0, 0, 256, 98, @betting_GoldWon.to_s,1)
  end
  #--------------------------------------------
  ##############Update#########################
  #--------------------------------------------
  def update
    super
    if $game_variables[1] != @betting_Wins or $game_variables[2] != @betting_GoldWon
      @betting_Wins=$game_variables[1]
      @betting_GoldWon=$game_variables[2]
      refresh
      end  
  end
end

Redrawing takes a lot of processing time, so you don't want to call for a refresh unless it's necessary. That's why we use update, which checks the variables and should call for a refresh if the window needs to be redrawn
So redrawing shouldn't have to call for a update in the variables.

Anyway, make an event and have it run the code:
CODE
@betting_window = Window_Betting.new

Then have the event have a loop, and inside the loop have a wait 1 frame, and the snippet of code
CODE
@betting_window.update
The last thing you should have in the loop would be something like:
If Switch 001: Break Loop == true
Break Loop
so you can tell the event to dispose the window when you are done gambling.
After of the loop, have the event run the code
CODE
@window_betting.dispose



And that should show your window smile.gif

Or would you like me to make the event and upload a demo?
Sir_Ver
QUOTE (Night_Runner @ Jul 26 2011, 05:57 AM) *
Hello Sir_Ver smile.gif

I just wanted to say, you have @B at the start of a lot of variable names, never start your variable names with capital letters.
Capitalised first letters are reserved for class names and constants.

And one more slight edit to your code:
CODE
class Window_Betting < Window_Base
  #-----------------------------------------
  ######Object Initialization###############
  #-----------------------------------------
  attr_accessor   :variable
  def initialize
    super (0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    #Wins and Losses
    @betting_Wins=$game_variables[1]
    @betting_GoldWon=$game_variables[2]
    refresh
end
  #-------------------------------------------
  #############Refresh########################
  #-------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 256, 32, "Dice Gamble", 1)
    self.contents.draw_text(0, 0, 256, 64, "Wins")
    self.contents.draw_text(0, 0, 256, 64, @betting_Wins.to_s, 1)
    self.contents.draw_text(0, 0, 256, 98, "Gold Won")
    self.contents.draw_text(0, 0, 256, 98, @betting_GoldWon.to_s,1)
  end
  #--------------------------------------------
  ##############Update#########################
  #--------------------------------------------
  def update
    super
    if $game_variables[1] != @betting_Wins or $game_variables[2] != @betting_GoldWon
      @betting_Wins=$game_variables[1]
      @betting_GoldWon=$game_variables[2]
      refresh
      end  
  end
end

Redrawing takes a lot of processing time, so you don't want to call for a refresh unless it's necessary. That's why we use update, which checks the variables and should call for a refresh if the window needs to be redrawn
So redrawing shouldn't have to call for a update in the variables.

Anyway, make an event and have it run the code:
CODE
@betting_window = Window_Betting.new

Then have the event have a loop, and inside the loop have a wait 1 frame, and the snippet of code
CODE
@betting_window.update
The last thing you should have in the loop would be something like:
If Switch 001: Break Loop == true
Break Loop
so you can tell the event to dispose the window when you are done gambling.
After of the loop, have the event run the code
CODE
@window_betting.dispose



And that should show your window smile.gif

Or would you like me to make the event and upload a demo?


@Night Runner
Thank you very much for having a go at helping me learn to code. It's a hard process for me. And I'm thankful you have taken the time.
EDIT: My bad, I figured it out. It works great, thank you!

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.