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.

Why isn't this script working right?

The script in question *credit to TheScripter*

Code:
 

 Bitmaps = ["Small House- Page 1", "Small House- Page 2", "Small House- Page 3", 

  "Small House- Page 4", "Small House- Page 5"]

 

#==============================================================================

# ** Sprite_Book

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Scene_Book_A

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @index = 0

    @size = Bitmaps.size

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make graphic

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture(Bitmaps[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 graphic

    @sprite.bitmap.dispose

    @sprite.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::RIGHT)

      next_page

    end

    if Input.trigger?(Input::LEFT)

      previous_page

    end

  end

  #--------------------------------------------------------------------------

  # * Next Page

  #--------------------------------------------------------------------------

  def next_page

    if @index != (@size - 1)

      @index += 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      $scene = Scene_Map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Previous Page

  #--------------------------------------------------------------------------

  def previous_page

    if @index != 0

      @index -= 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)     

      else

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

    end

  end

end

 

############

#Letter 2##

############

 

Bitmaps = ["LH Hunting Page 1", "LH Hunting Page 2", "LH Hunting Page 3"]

 

 

#==============================================================================

# ** Sprite_Book

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Scene_Book2

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @index = 0

    @size = Bitmaps.size

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make graphic

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture(Bitmaps[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 graphic

    @sprite.bitmap.dispose

    @sprite.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::RIGHT)

      next_page

    end

    if Input.trigger?(Input::LEFT)

      previous_page

    end

  end

  #--------------------------------------------------------------------------

  # * Next Page

  #--------------------------------------------------------------------------

  def next_page

    if @index != (@size - 1)

      @index += 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      $scene = Scene_Map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Previous Page

  #--------------------------------------------------------------------------

  def previous_page

    if @index != 0

      @index -= 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)     

      else

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

    end

  end

end

 

Bitmaps = ["LH Can 1", "LH Can 2"]

 

 

#==============================================================================

# ** Sprite_Book

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Scene_Book3

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @index = 0

    @size = Bitmaps.size

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make graphic

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture(Bitmaps[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 graphic

    @sprite.bitmap.dispose

    @sprite.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::RIGHT)

      next_page

    end

    if Input.trigger?(Input::LEFT)

      previous_page

    end

  end

  #--------------------------------------------------------------------------

  # * Next Page

  #--------------------------------------------------------------------------

  def next_page

    if @index != (@size - 1)

      @index += 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      $scene = Scene_Map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Previous Page

  #--------------------------------------------------------------------------

  def previous_page

    if @index != 0

      @index -= 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@index])

      $game_system.se_play($data_system.actor_collapse_se)     

      else

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

    end

  end

end

The event I have is set up similar to this.

Move Event- Player
> script: $scene = Scene_Book_A.new
> wait 20 frames

This was working fine, and for the others I'd use the same event, only call one of the other scenes. The weird thing is out of no where, this stopped working. No matter what, the script works as if I called Scene_Book3, all the time. Anyone know what the problem could be?
 
Are all of the classes the same, except with different names? There's a much more efficient way of doing that. It looks like the problem is that all three use the same Bitmaps array, so the 3rd one always overwrites the other two.

Try this instead:

Code:
 

# Set bitmaps

Bitmaps = [

  ["Small House- Page 1", "Small House- Page 2", "Small House- Page 3",

  "Small House- Page 4", "Small House- Page 5"], # Book 1

 

  ["LH Hunting Page 1", "LH Hunting Page 2", "LH Hunting Page 3"], # Book 2

 

  ["LH Can 1", "LH Can 2"] # Book 3

]

#==============================================================================

# ** Sprite_Book

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Scene_Book

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(value = 1)

    @book = value - 1

    @index = 0

    @size = Bitmaps[@book].size

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make graphic

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.picture(Bitmaps[@book][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 graphic

    @sprite.bitmap.dispose

    @sprite.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::RIGHT)

      next_page

    end

    if Input.trigger?(Input::LEFT)

      previous_page

    end

  end

  #--------------------------------------------------------------------------

  # * Next Page

  #--------------------------------------------------------------------------

  def next_page

    if @index != (@size - 1)

      @index += 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@book][@index])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      $scene = Scene_Map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Previous Page

  #--------------------------------------------------------------------------

  def previous_page

    if @index != 0

      @index -= 1

      @sprite.bitmap = RPG::Cache.picture(Bitmaps[@book][@index])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

    end

  end

end

Now all you need to call is:
$scene = Scene_Book.new(value)

where value is the Book ID you want.
 
regi":3e2rura7 said:
Are all of the classes the same, except with different names? There's a much more efficient way of doing that. It looks like the problem is that all three use the same Bitmaps array, so the 3rd one always overwrites the other two.

Try this instead:

Code:
 

# Set bitmaps

Bitmaps = {

  ["Small House- Page 1", "Small House- Page 2", "Small House- Page 3",

  "Small House- Page 4", "Small House- Page 5"], # Book 1

 

  ["LH Hunting Page 1", "LH Hunting Page 2", "LH Hunting Page 3"], # Book 2

 

  ["LH Can 1", "LH Can 2"] # Book 3

}

#==============================================================================

# ** Sprite_Book

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Scene_Book

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(value = 1)

     = value - 1

     = 0

     = Bitmaps[].size

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make graphic

     = Sprite.new

    .bitmap = RPG::Cache.picture(Bitmaps[[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 graphic

    .bitmap.dispose

    .dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if Input.trigger?(Input::RIGHT)

      next_page

    end

    if Input.trigger?(Input::LEFT)

      previous_page

    end

  end

  #--------------------------------------------------------------------------

  # * Next Page

  #--------------------------------------------------------------------------

  def next_page

    if  != ( - 1)

       += 1

      .bitmap = RPG::Cache.picture(Bitmaps[[]])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      $scene = Scene_Map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Previous Page

  #--------------------------------------------------------------------------

  def previous_page

    if  != 0

       -= 1

      .bitmap = RPG::Cache.picture(Bitmaps[[]])

      $game_system.se_play($data_system.actor_collapse_se)    

      else

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

    end

  end

end

Now all you need to call is:
$scene = Scene_Book.new(value)

where value is the Book ID you want.
First off, thank you very much for taking the time to make that.

Secondly, I get a syntax error on line 9 when using this :P. I'm not sure what the problem is.
 
regi":1b9sy0gh said:
My bad :| that's the problem with releasing something without being able to test it.
Fixed up my first post (one with the script), try that.
Thanks a lot man, this works great. Now I can finally get back to work :P.

Also, if I want to add any other letter, do I just pretty much copy and paste what you have setup?
 
All you need to do is add to the Bitmaps array.

So if you wanted a book with two more pages, you'd simply edit:
Code:
Bitmaps = {

  ["Small House- Page 1", "Small House- Page 2", "Small House- Page 3",

  "Small House- Page 4", "Small House- Page 5"], # Book 1

 

  ["LH Hunting Page 1", "LH Hunting Page 2", "LH Hunting Page 3"], # Book 2

 

  ["LH Can 1", "LH Can 2"], # Book 3

 

  ["New Book Page 1", "New Book Page 2"] # Book 4 <-------------

}
and call it with $scene = Scene_Book.new(4)

Just make sure to add a comma after each book, except for the last one:

["...", "...", "..."],
 

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