[RESOLVED] Another problem with script I'm writing

Started by Ryex, June 05, 2008, 10:41:56 pm

Previous topic - Next topic

Ryex

June 05, 2008, 10:41:56 pm Last Edit: July 25, 2008, 04:58:46 pm by Starrodkirby86
I'm writing a CMS and i has just finished one of my windows so i decided to try and display it and see what it looked like  but as soon

heres the whole script so far

please note that this script is not complete and is in its earliest stages

#=============================================================================
#
# ** Collapsed_CMS
#
#-----------------------------------------------------------------------------
#
# By Ryex
# V 0.01
#
#=============================================================================
#==============================================================================
# ** Window_HCommand By Blizzard
#------------------------------------------------------------------------------
#  This window deals with general command choices, but the display is
#  horizontal.
#==============================================================================

class Window_HCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     width    : window width
  #     commands : command text string array
  #--------------------------------------------------------------------------
  def initialize(width, commands)
    super
    self.width, self.height = commands.size * width + 32, 64
    @column_max = commands.size
    self.contents.dispose
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(i, color)
    self.contents.font.color = color
    w = (self.width - 32) / @column_max
    x = i % @column_max * w
    rect = Rect.new(x, 0, self.contents.width / @column_max, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[i], 1)
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index / @column_max
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = (self.width - 32) / @column_max
    # Calculate cursor coordinates
    x = @index % @column_max * cursor_width
    # Update cursor rectangle
    self.cursor_rect.set(x, 0, cursor_width, 32)
  end
end

#==============================================================================
# ** Window_CollapsedMenuStatus By Ryex
#------------------------------------------------------------------------------
#  This window displays limited party member stats horizontaly in the menu.
#==============================================================================

class Window_CollapsedMenuStatus < Window_Base
  #----------------------------------------------------------------------------
  # * Object Initialization
  #     x : x value
  #     y : y value
  #----------------------------------------------------------------------------
def initialize(x, y)
    super(x, y, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Draw a % bar of a certen langth (you must provide the amount)
  #     x : x value
  #     y : y value
  #     p : % fill
  #     m : max leinght
  #     r : Red value
  #     g : Green value
  #     b : Blue value
  #--------------------------------------------------------------------------
  def draw_bar(x,y,p,m1,r,g,b)
    self.contents.fill_rect(x, y - 1, m1, 14, Color.new(0, 0, 0))
    m2 = m1 - 2
    self.contents.fill_rect(x + 1, y, p * m2, 12, Color.new(r, g, b))
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      actorx = i * 160 + 4
      draw_actor_name(actor, actorx, 0)
      rate1 = actor.hp / actor.maxhp
      draw_bar(actorx, 40, rate1, 120, 255, 0, 0)
      draw_actor_hp(actor, actorx, 32, 120)
      rate2 = actor.sp / actor.maxhp
      draw_bar(actorx, 72, rate2, 120, 0, 0, 255)
      draw_actor_sp(actor, actorx, 64, 120)
      rate3 = $game_party.actors[i].exp / $game_party.actors[i].next_exp_s.to_i
      draw_bar(actorx, 102, rate3, 120, 255, 255, 0)
      self.contents.draw_text(actorx, 96, 32, 120, "NEXT LEVEL")
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
  end
end



#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================

class Scene_Menu
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Save"
    s6 = "End Game"
    @command_window = Window_HCommand.new(96, [s1, s2, s3, s4, s5, s6])
    @command_window.x = 16
    @command_window.y = 416
    @command_window.index = @menu_index
    # If number of party members is 0
    if $game_party.actors.size == 0
      # Disable items, skills, equipment, and status
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # If save is forbidden
    if $game_system.save_disabled
      # Disable save
      @command_window.disable_item(4)
    end
    # Make status window
    @status_window = Window_CollapsedMenuStatus.new(0,0)
    @status_window.x = 0
    @status_window.y = 0
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    @status_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
    # If status window is active: call update_status
    if @status_window.active
      update_status
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when command window is active)
  #--------------------------------------------------------------------------
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 4  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to save screen
        $scene = Scene_Save.new
      when 5  # end game
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when status window is active)
  #--------------------------------------------------------------------------
  def update_status
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Make command window active
      @command_window.active = true
      @status_window.active = false
      @status_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by command window cursor position
      case @command_window.index
      when 1  # skill
        # If this actor's action limit is 2 or more
        if $game_party.actors[@status_window.index].restriction >= 2
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to skill screen
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to equipment screen
        $scene = Scene_Equip.new(@status_window.index)
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to status screen
        $scene = Scene_Status.new(@status_window.index)
      end
      return
    end
  end
end
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Aqua

Not much of a scripter but shouldn't
rate2 = actor.sp * 100 / actor.maxhp

be
rate2 = actor.sp * 100 / actor.maxsp

Juan

Actually Aqua that is correct. You also should change
draw_actor_sp(actor, actorx, 64, 120 
to
draw_actor_sp(actor, actorx, 64, 120)
I think you forgot a ) in that line of code.
Dropbox Who need luck when you can make your own.
3ds Friend code: ShowHide
 4468 1422  6617

Ryex

lol Aqua your right! must of not been paying attention when I did that, but that is not what is causing the error

@Juan look a bit closer there is indeed a ")" at the end of the line in the main script
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Ryex

hello?

I'm sorry but the problem isn't fixed yet...

I've obviously done some thing wrong that is so simple that i should be killed for the mistake but I still Can't figure out whats wrong.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

At the end, in def refresh, in each line that says "self.contents.fill_rect(...", there's a closed parenthesis ")" missing.

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

yep i knew it some thing really stupid on my part. thanks bliz. I can't believe I didn't notice that...

you know what we need a smack's face icon face
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

We need a lot of smileys. I just lack the time to add them. ._.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

June 20, 2008, 12:05:40 am #8 Last Edit: June 21, 2008, 10:15:44 am by Ryex
I'm recycling this topic.

the script in the first post has been modified to be the latest version please not yet again it is not finished and represents a work in progress

I'm having a new problem


  • the first problem is that two of the sp bars (the first two) aren't working

  • the second problem is when ever I'm in a battle and loss health so that I'm not at max hp the hp bars don't work

  • the third problem none of the experience bars are working

  • the forth problem the text "NEXT LEVEL" is not showing up on the exp bars


I don't know what is causing any of them  though the first two is probably a problem with how I calculated the width of the bars but I'm not sure and nothing I've tried so far has helped at all. help would be wonderful. thanks in advance
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

June 23, 2008, 03:58:26 am #10 Last Edit: June 23, 2008, 06:22:20 am by Blizzard
Alright, I told myself that if you bump this topic, I'll solve your problem. Just give me a couple of minutes until I check out all the new posts at the forum.

EDIT:

Use this code for your windows:

  #--------------------------------------------------------------------------
  # * Draw a % bar of a certen length (you must provide the amount)
  #     x : x value
  #     y : y value
  #     p : % fill
  #     m : max leinght
  #     c : color
  #--------------------------------------------------------------------------
  def draw_bar(x, y, p, m1, c)
    self.contents.fill_rect(x, y - 1, m1, 14, Color.new(0, 0, 0))
    self.contents.fill_rect(x + 1, y, p * (m1 - 2), 12, c)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      actorx = i * 160 + 4
      draw_actor_name(actor, actorx, 0)
      rate1 = actor.hp.to_f / actor.maxhp
      draw_bar(actorx, 40, rate1, 120, Color.new(255, 0, 0))
      draw_actor_hp(actor, actorx, 32, 120)
      rate2 = actor.sp.to_f / actor.maxsp
      draw_bar(actorx, 72, rate2, 120, Color.new(0, 0, 255))
      draw_actor_sp(actor, actorx, 64, 120)
      self.contents.draw_text(actorx, 96, 32, 120, "NEXT LEVEL")
      rate3 = $game_party.actors[i].exp / $game_party.actors[i].next_exp_s.to_i
      draw_bar(actorx, 102, rate3, 120, Color.new(255, 255, 0))
    end
  end


You had two errors. The first was that you used "rate2 = actor.sp / actor.maxhp" instead of "rate2 = actor.sp / actor.maxsp". The second was that you were using the wrong number type. Integers are always integers, that means if you divide 1435 by 1436 you will get 0 as the result and an empty bar. You need to add ".to_f" which will convert that number to a floating point number which is used to represent decimal numbers. Doing mathematical operations with integers and floats will give floats as result so only one ".to_f" is necessary. That results in "rate2 = actor.sp.to_f / actor.maxsp". I changed the way you call your method, BTW. I don't know how to solve the problem in battle as you haven't provided the code that you use in battle. :P
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz


Ryex

oh the problem wasn't in battle but I think that this will solve it any way

so floating point numbers?  well I still have a lot to learn about scripting is seems. lol

thanks for the help.

@Calintz if Blizzard wasn't nice would anything happen around here?

hopefully i can get to the point where I can solve these things myself! that way Blizzard wouldn't feel inclined be so nice!
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />