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.

how would i?

how would i implement this piece of code
Code:
class Scene_Menu

  alias main_menu_back main

  def main

    @spriteset = Spriteset_Map.new

    main_menu_back

    @spriteset.dispose

  end

end

Into this script
Code:
#---------------------------------------------------------------------

#Test script

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

 

class Scene_Chapter3_menu1

 

def initialize(menu_index = 0)

@menu_index = menu_index #Store the cursor position

end

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

 

 

def main

@window_a1=Window_a1.new #Content Window

@window_a1.update(false) #Decide whether to show/hide the content...

@window_a1.x=218

@window_a1.y=400

 

s1 = "Items"

s2 = "Infos"

s3 = "Music A"

s4 = "Music B"

s5 = "Exit"

@window_a2 = Window_Command.new(200, [s1,s2,s3,s4,s5]) #Remember, 200 is the Width

@window_a2.y=400#Set a position for the menu other than 0:0

@window_a2.x=290

@window_a2.width=350

@window_a2.height=80 #Force a new height for the menu window

@window_a2.index = @menu_index

 

 

#This is what makes the scene update itself constantly:

Graphics.transition

loop do

Graphics.update

Input.update

update #Call the method DEF UPDATE starting below

if $scene != self

break

end

end

 

 

#Execute when exiting the scene:

Graphics.freeze

@window_a1.dispose

@window_a2.dispose

$scene = Scene_Map.new

end

 

 

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

 

def update

 

@window_a2.update #menu

 

if Input.trigger?(Input::B) #Press ESCAPE to exit

$game_system.se_play($data_system.cancel_se)

$scene = Scene_Map.new

$game_map.autoplay #Because we play music in the menu...

end

 

end

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

 

#Options Method Start Here:

 

 

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

end #of the Scene !

 

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

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

 

 

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

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

class Window_a1 < Window_Base

 

def initialize

super(300, 300, 50,80)

self.contents = Bitmap.new(width-32, height-32)

self.contents.font.name = "Tahoma"

self.contents.font.size = 20

end

 

def update(content) #Receive the argument from the menu

if content == false #If false, don't show content

self.contents.clear

self.contents.draw_text(0, 0, 120, 32, "No Content...")

else #else, if true, show it...

self.contents.clear

self.contents.draw_text(0, 0, 440, 32, "SHOW CONTENT")

end

end

 

end

 

  

 

 

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

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

 
 
Well, you simply need to modify your main method in the second script... that'd look like this:

Code:
def main

  @spriteset = Spriteset_Map.new

  @window_a1 = Window_a1.new #Content Window

  @window_a1.update(false) #Decide whether to show/hide the content...

  @window_a1.x = 218

  @window_a1.y = 400

  s1 = "Items"; s2 = "Infos"; s3 = "Music A"; s4 = "Music B"; s5 = "Exit"

  @window_a2 = Window_Command.new(200, [s1, s2, s3, s4, s5]) # Remember, 200 is the Width

  @window_a2.y = 400 # Set a position for the menu other than 0:0

  @window_a2.x = 290

  @window_a2.width = 350

  @window_a2.height = 80 # Force a new height for the menu window

  @window_a2.index = @menu_index

 

  # This is what makes the scene update itself constantly:

  Graphics.transition

  loop do

    Graphics.update

    Input.update

    update # Call the method UPDATE starting below

    if $scene != self

      break

    end

  end

  

  # Execute when exiting the scene:

  Graphics.freeze

  @window_a1.dispose

  @window_a2.dispose

  @spriteset.dispose

  $scene = Scene_Map.new

end

Note how I corrected some of your script formatting errors there... identation is a very important thing in even small code pieces, so yeah - learn to use it!
Other than that, if you're going for clean code - what you should - choose more distinct names for your containers. window_a1 is almost as bad as it gets, with the exception that you at least get to know it's a window :p If you simply name it window_content, you also save that comment in the same line as it's initialization call.

Also, remember that to see the map background behind your menu, you need to make your windows semi-transparent using @window_name.back_opacity = value, while value is a number between 0 and 255.
 

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