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.

Birthday script!

This is a small and easy request.  It will probably take anybody like 5 minutes to do.  But I'm still in the learning stages!

I'd like a script (let's call it Window_Birthday for the purpose of discussion) that pops up in an event.  So on an event on a map somewhere, a line of code is put in a event script box that calls Window_Birthday.  What Window_Birthday does is it pops up two windows, the first containing 'January' and the other containing '1st'.  You can move the cursor between the two boxes and change the date to whatever you want the birthday of your character to be set at.  If you're set to a 31st, say December 31st, and you flip to a month that does NOT have a 31st, say November, the date cursor should flip back to the previous day (the 30th.)  February should not have the 29th included.  There doesn't have to be an indication to select a year either.  Just month and day.

Ms Paint'd image of what I'm talking about, for design/box placement purposes (Approximately, it IS MSPaint :P ):
http://xs222.xs.to/xs222/07500/birthday.png[/img]

Thanks to anybody that could do this for me!

Edit - So thinking about it a bit, if you wanted a more clear idea of what I'm looking for, I'm thinking the Birthday Entry from Ogre Battle 64 at the beginning of the game.  Just in case people have no idea what I'm talking about.  :P
 
I've tried a few times the past 3 days to do this and have been unsuccessful so...

bump!  please help!

Edit for adding my attempt :

Code:
#==============================================================================
# â–  Scene_birthday
#------------------------------------------------------------------------------
#  this is for birthdays
#==============================================================================

class Scene_Birthday
  #--------------------------------------------------------------------------
  # â—
 
Window_Birthday

#==============================================================================
# ** Window_Birthday
#------------------------------------------------------------------------------
#  This window is used to select birth date
#==============================================================================

class Window_Birthday < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    @index = 0
      @months =
  [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
  ]
  @days =
  [
    "1st",
    "2nd",
    "3rd",
    "4th",
    "5th",
    "6th",
    "7th",
    "8th",
    "9th",
    "10th",
    "11th",
    "12th",
    "13th",
    "14th",
    "15th",
    "16th",
    "17th",
    "18th",
    "19th",
    "20th",
    "21st",
    "22nd",
    "23rd",
    "24th",
    "25th",
    "26th",
    "27th",
    "28th",
    "29th",
    "30th",
    "31st",
  ]
 
  @mymonth = 1
  @myday = 1
  @selection = 0 #0 = month, 1 = day
    refresh
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    #Header
    self.contents.draw_text(0, 40, 640, 32, "Enter Your Birthday", 1)
    self.contents.draw_text(0, 70, 640, 32, "Left/Right = Choose, Up/Down = Change", 1)
    #Current month
    self.contents.draw_text(200, 120, 100, 32, @months[@mymonth - 1].to_s, 0)
    #Current day
    self.contents.draw_text(300, 120, 100, 32, @days[@myday - 1].to_s, 0)
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if (@selection == 0)
      #Selecting Month
        x = 195
        y = 115
    end
   
    if (@selection == 1)
        x = 295
        y = 115
    end
      self.cursor_rect.set(x, y, 96, 32)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
      if Input.trigger?(Input::DOWN)
        #Down change
        $game_system.se_play($data_system.cursor_se)
        if (@selection == 0)
          #changing MONTH
          @mymonth += 1
          if (@mymonth == 13)
            @mymonth = 1
          end
         
          #Check days and change if invalid date
          if (@mymonth == 2)
            if (@myday > 29)
              @myday = 29
            end
          end
          if (@mymonth == 4)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 6)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 9)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 11)
            if (@myday > 30)
              @myday = 30
            end
          end
        end
        if (@selection == 1)
          #Changing DAY
          @myday += 1
          if (@myday > 31)
            @myday = 1
          end
          #Check for months with fewer that 31 days
          if (@mymonth == 2)
            if (@myday > 29)
              @myday = 1
            end
          end
          if (@mymonth == 4)
            if (@myday > 30)
              @myday = 1
            end
          end
          if (@mymonth == 6)
            if (@myday > 30)
              @myday = 1
            end
          end
          if (@mymonth == 9)
            if (@myday > 30)
              @myday = 1
            end
          end
          if (@mymonth == 11)
            if (@myday > 30)
              @myday = 1
            end
          end
        end
        refresh
      end

      if Input.repeat?(Input::UP)
        #Up change
        $game_system.se_play($data_system.cursor_se)
        if (@selection == 0)
          #changing MONTH
          @mymonth -= 1
          if (@mymonth == 0)
            @mymonth = 12
          end
         
          #Check days and change if invalid date
          if (@mymonth == 2)
            if (@myday > 29)
              @myday = 29
            end
          end
          if (@mymonth == 4)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 6)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 9)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 11)
            if (@myday > 30)
              @myday = 30
            end
          end
        end
        if (@selection == 1)
          #Changing DAY
          @myday -= 1
          if (@myday < 1)
            @myday = 31
          end
          #Check for months with fewer that 31 days
          if (@mymonth == 2)
            if (@myday > 29)
              @myday = 29
            end
          end
          if (@mymonth == 4)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 6)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 9)
            if (@myday > 30)
              @myday = 30
            end
          end
          if (@mymonth == 11)
            if (@myday > 30)
              @myday = 30
            end
          end
        end
        refresh
      end

      if Input.trigger?(Input::RIGHT) or Input.trigger?(Input::LEFT)
        $game_system.se_play($data_system.cursor_se)
        if (@selection == 0)
              @selection = 1
        else
              @selection = 0
        end
      end
     
      if Input.trigger?(Input::C)
      #At this point the user pressed the action button, so you'd store either
      #the numerical dates (@mymonth and @myday) into variables, or the text
      #(@months[@mymonth] and @days[@myday]) if you prefer that.  For example:
     
      #$game_variables[1] = @mymonth
      #$game_variables[2] = @myday
     
      $game_system.se_play($data_system.decision_se)
      return
      end
      update_cursor_rect
  end
end

Scene_Birthday
#==============================================================================
# ** Scene_Birthday
#------------------------------------------------------------------------------
#  This class performs birthday handling
#==============================================================================

class Scene_Birthday
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @input_window = Window_Birthday.new
    # 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
    @input_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @input_window.update
    if Input.trigger?(Input::C)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
      return
  end
end

Call:

$scene = Scene_Birthday.new
 
I've been playing around with this too. I was looking at Window_InputNumber, and Window_Command for inspiration.
I was going after a slightly different logic, using a single index that pointed to either month or day. Then using UP & DOWN keys to change the field to the next value, and
the RIGHT & LEFT keys to switch fields (& change the index).
Then, the ENTER key would close the window & store the values.
I also made it a little generic (Enter Date), so it can be reused if anyone else needs it.

Here's what I have so far:

Code:
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================

class Window_Date < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     width    : window width
  #     commands : command text string array
  #--------------------------------------------------------------------------
  def initialize
    super(192, 192, 200, 92)
    @digits_max = 2
    @day = 1
    @months = ["Jan", "Feb", "Mar", 
               "Apr", "May", "Jun",
               "Jul", "Aug", "Sep",
               "Oct", "Nov", "Dec"]
    @month = 1
    # Days Per Month
    @dpm = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    # Calculate cursor width from number width (0-9 equal width and postulate)
    dummy_bitmap = Bitmap.new(32, 32)
    @cursor_width = dummy_bitmap.text_size("0").width * 3 + 8
    dummy_bitmap.dispose
    self.contents = Bitmap.new(168, 64)
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    self.cursor_rect.set(@index * @cursor_width, 32, @cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 110, 32, "Enter Date", 1)
    self.contents.draw_text(4, 32, 36, 32, @months[@month])
    self.contents.draw_text(40, 32, 36, 32, @day.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If up directional button was pressed
    if Input.repeat?(Input::UP)
      $game_system.se_play($data_system.cursor_se)
      # If changing month
      if @index == 0
        @month = (@month < 12 ? @month + 1 : 1)
        @day = (@day > @dpm[@month] ? @dpm[@month] : @day)
      # If changing day
      end
      if @index == 1
        @day = (@day < @dpm[@month] ? @day + 1 : 1)
      end
      refresh
    end
    # If down directional button was pressed
    if Input.repeat?(Input::DOWN)
      $game_system.se_play($data_system.cursor_se)
      # If changing month
      if @index == 0
        @month = (@month > 1 ? @month - 1 : 12)
        @day = (@day > @dpm[@month] ? @dpm[@month] : @day)
      end
      # If changing day
      if @index == 1
        @day = (@day > 1 ? @day - 1 : @dpm[@month])
      end
      refresh
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      if @digits_max >= 2
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + 1) % @digits_max
      end
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      if @digits_max >= 2
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + @digits_max - 1) % @digits_max
      end
    end
    update_cursor_rect
  end
end

You can see I used the @dpm (days per month) array, to reset the day value to the dpm of the new month if the old day value is too high.

Since this is being called on Scene_Map, I need to figure out how to get my update method to work. Right now it just returns control to the map, and the player moves with the arrow keys instead of the month or day changing. I assume I need to
overload the update method from Scene_Map so it 'pauses' or skips that update.

And you thought this was going to be easy!  :)  (maybe for the squids)

I'll keep plugging along, and I'll try out your script as well.

Be Well
 
$new_window = Window_Date.new

I was trying to make it display in the Map scene, so I didn't
want to overwrite $scene

If you don't mind it being it's own scene, then let's work with Deltree's
version, and just pretty it up.

I still want to figure out how to make it work on the Map scene though.

Be Well
 
Brewmeister":i55qt140 said:
$new_window = Window_Date.new

I was trying to make it display in the Map scene, so I didn't
want to overwrite $scene

If you don't mind it being it's own scene, then let's work with Deltree's
version, and just pretty it up.

I still want to figure out how to make it work on the Map scene though.

Be Well

Sorry for taking so long to reply, I've been in transit the last few days on the way home for winter break.

Personally, either-or works - I'd like the spite and map to appear behind the enter birthday window, so making it work on the map or having its own scene using the background/spriteset method achieves the same result for me.  But people in the future may want something else!

Thanks for your help guys.
 

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