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.

Making a Simple Menu

I'm a newbie at RGSS, I've been looking over the terms and such, but I don't think I understand them fully.

I was trying to script a small script that would Open up a menu, when I pressed a certain key.
When I went in-game, and pressed the button, the menu didn't show. Can anyone help me with the problem? Here's the code.

Code:
#-------------------------------------------------------------------------------
# I wanna Script
#-------------------------------------------------------------------------------
class Scene_Window
#-------------------------------------------------------------------------------
# Define the Menu's
#-------------------------------------------------------------------------------
 def initialize(menu_index = 0)
   @menu_index = menu_index
 end
#-------------------------------------------------------------------------------
  def main
    s1 = "I"
    s2 = "Wanna"
    s3 = "SCRIPT"
    @command_window = Window_Command.new(160, [s1, s2, s3,])
    @command_window.index = @menu_index
    @command_window.dispose
  end
#----------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
#---------------------------------------------------------------------------
  def update_command
    if Input.trigger?(Input::J)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Window.new
      return
    end
  end
end
end
 
First of all, I don't think the default input keys supports "J". For that 2 work you would have to implement an input module. I would suggest "L", which is the Q key on the keyboard by default.

Also, from where did you try to call the Scene? If callin the scene is actually in Scene_Window, nothing will happen. You have to edit Scene_Map if you would like to call it from the map. Otherwise, you could try adding another selectable in the menu.

But I'm glad you're trying. I'm a beginner myself... :lol:
 
Where to start lol.
There's several problems with how you've done this.
Firstly, you only call your scene from inside the class meaning it's never actually called. Even if it was called, your main method creates a new version of the window
Code:
@command_window = Window_Command.new(160,[s1,s2,s3])
but dispose of the window directly after
Code:
@command_window.dispose
Since you're not using the Graphics.transition method, it will never actually draw the window on screen.

you then go on to define an update method, but never call it in the main method.

Here's a working version of your scene, I suggest going to a tutorial (try searching dubealex's tutorial for CMS or Leon's CMS tutorial) for a proper explanation.
Code:
#---------------------------------------------------------
#I wanna script
#---------------------------------------------------------
class Scene_Window
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end

  def main
    s1 = 'I'
    s2 = 'Wanna'
    s3 = 'Script'
    @command_window = Window_Command.new(160,[s1,s2,s3])
    @command_window.index = @menu_index
    Graphics.transition
    loop do
      Input.update
      Graphics.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @command_window.dispose
  end

  def update
    @command_window.update
    #Since you've only got the one window which should allways be active
    #the following is not strictly necessary but I'll add it anyway
    if @command_window.active
    update_command
  end

  def update_command
    #I'm just gonna put a way to get out of the menu onto the map, 
    #since you're already IN Scene_Window
    if Input.trigger?(Input::B) #esc/x? button
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    end
  end
end
Note that pressing any button in the menu other than escape won't actually do anything, you'll basically just be able to highlight the options unless you put a case statement or the like in the update_command method.
To call this, you can create an event with a script call saying $scene = Scene_Map.new
Basically, the Graphics.transition is needed to draw any graphics. When a scene is exited, Graphics.freeze is called (as you can see in this class as well) which stops the graphics from updating until Graphics.transition is called, so that windows will all be drawn at the same time neatly etc.
The loop do is an infinite loop updating the input, graphics and window itself. These are always called like that as a general rule to ensure all this things function properly. The break statement means it breaks out of the loop as soon as the scene becomes different (i.e. Scene_Map instead of Scene_Window)
then comes "Graphics.freeze", which I already explained, followed by the disposal of any windows you've created.
The actual update method just calls Window_Command's update method which allows movement of the cursor etc. and then, the update_command method puts in a clause for when the B(esc) button is pressed, to change the scene to Scene_Map. Hope that clears things up somewhat, but I still suggest reading one of those tute's they're quite good
 
I understand the concept of having to make other windows for those selections. I was trying to make a simple window/menu show up, but I didn't know it took that much to make one show up  :crazy:. Thanks a lot.
 
haha, it's not as much as it seems really. Once you get used to it a lot of the stuff becomes extremely automatic.
Also, if you want the window to pop-up directly from the map, rather than through an event, you would have to change Scene_Map's update method.
i.e. for your menu you could simply add
Code:
if Input.trigger?(Input::J)
  $scene = Scene_Window.new
end
provided you have the J input in your custom input module of course
 

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