Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Updating/Refreshing window
Sir_Ver
post Jul 25 2011, 03:03 AM
Post #1



Group Icon

Group: Member
Posts: 2
Type: Developer
RM Skill: Intermediate




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
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Jul 26 2011, 04:57 AM
Post #2


Level 50
Group Icon

Group: +Gold Member
Posts: 1,522
Type: Scripter
RM Skill: Undisclosed




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?


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Sir_Ver
post Jul 26 2011, 09:24 PM
Post #3



Group Icon

Group: Member
Posts: 2
Type: Developer
RM Skill: Intermediate




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 post has been edited by Sir_Ver: Jul 28 2011, 01:27 AM
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 12:46 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker