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.

Command window not displaying?

I'm writing this script for interaction with an evented AI. The script works fine, but the command window isn't visible at all.

Code:
class Scene_AutoPilot

  

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

  # * Object Initialization

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

  def initialize(menu_index = 0)

    @menu_index = menu_index

  end

 

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

  # * Main

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

  def main

    # Make sprite set

    @spriteset = Spriteset_Map.new

    # Make command window

    s1 = "Rabanastre"

    s2 = "Giza Plains"

    @command_window = Window_Command.new(160, [s1, s2])

    @command_window.index = @menu_index

    # Determine whether each location can be visited or not.

    if $game_switches[4] == false       # Rabanastre

      @command_window.disable_item(0)

    end

    # 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

  end

 

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

  # * Frame Update

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

  def update

    # Update windows

    @command_window.update

    # If command window is active: call update_command

    if @command_window.active

      update_command

      return

    end

  end

  

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

  # * Frame Update

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

  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)

      # Branch by command window cursor position

      case @command_window.index

      when 0  # Rabanastre

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Rabanastre

        $game_switches[101] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      when 1  # Giza Plains

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Giza Plains

        $game_switches[102] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      return

    end

  end

end

end

I know that it's something simple that I've just overlooked, but I have no idea what it is. How do I make the command window actually show up? This is only my second script ever, so take it easy. I want to learn though, so if you have any suggestions, let me know!

One thanks in advance!

EDIT: In addition to this, I'd really like it if I could completely take the option out if the switch isn't on. So, if switch 4 isn't on, the command window's list will only consist of "Giza Plains," because the first option, "Rabanastre," is completely omitted from the list. How do I go about doing this?
 
From what i see the code should work fine... :) maybe try positioning the window at different places and at different Z-ordering.
I also don't know why you create the spriteset_map..As it's not used in the scene anywhere else... it might be displayed over the window.... comment the line and test :)

Then instead of directly creating the array of options when calling the window_command.new, made of the s1 & s2 strings.
you could do a method to generate that array.

then the array could be filled rather than "set"... :) using the push method ->
[rgss] 
arr = [] # empty array
arr << "rabanastre" if ... # push rabanastre at the end of the array, which is currently the 1st position as the array is empty
arr << "giza" if .... # push giza to the end, which could be the 1st or 2nd position, depending on what happen at the previous line :)
 
# and so on.
# etc...
# I use << instead of .push , as it's prettier
 
 
 
 
[/rgss]
 
If I could make the array pushing work properly, that'd be perfect! I must've done something wrong though, and I don't quite understand some of it.

Code:
class Scene_AutoPilot

 

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

  # * Object Initialization

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

  def initialize(menu_index = 0)

    @menu_index = menu_index

  end

 

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

  # * Main

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

  def main

    #play sound effect

    $game_system.se_play($data_system.decision_se)

    # Make sprite set

    #@spriteset = Spriteset_Map.new

    # Make command window

    arr = [] # empty array

    arr << "rabanastre" if $game_switches[4] == true... # push rabanastre at the end of the array, which is currently the 1st position as the array is empty

    arr << "giza" if $game_switches[1] == true.... # push giza to the end, which could be the 1st or 2nd position, depending on what happen at the previous line :)

    @command_window = Window_Command.new(160, [s1, s2])

    @command_window.index = @menu_index

    # Determine whether each location can be visited or not.

    if $game_switches[4] == false       # Rabanastre

      @command_window.disable_item(0)

    end

    @command_window.active = true

    # 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

  end

 

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

  # * Frame Update

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

  def update

    # Update windows

    @command_window.update

    # If command window is active: call update_command

    if @command_window.active

      update_command

      return

    end

  end

 

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

  # * Frame Update

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

  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)

      # Branch by command window cursor position

      case @command_window.index

      when 0  # Rabanastre

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Rabanastre

        $game_switches[101] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      when 1  # Giza Plains

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Giza Plains

        $game_switches[102] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      return

    end

  end

end

end

I have a syntax error on line 21. I know that I'm missing some sort of closing statement, but I don't know what it is. Also, I tried taking out the spriteset_map because I thought that was how I overlayed the window onto the map. I've been scripting for two days, so I don't understand most of the syntax and stuff.

Could you go into more detail on how I create the array with the push method?

EDIT: Also, how do I change the window's z coordinate?
 
Well, It wouldn't work if there are no 2 elements to be pushed to the array... So change line 22 like this...

@command_window = Window_Command.new(160, arr)

But you gotta be sure there'll be at least one option included in the array or else...

Instead of...

if $scene != self
break
end

you could use...

break if $scene != self
 
Wonderful! Thanks :D!

It's still not visible though! I haven't set any .visible to false ever, so it can't be that. I tried setting the z to 999999, but that didn't work either. Are you sure that I didn't do something wrong?

EDIT: I also checked to see if the window was simply displaying outside of the screen's boundaries, but that isn't the case either. I've tried everything that I know to try - very little, mind you - and nothing has worked yet. Any help would be appreciated x.x

EDIT 2: In case this helps any, it doesn't seem that there are any options other than the first. Though I can't be sure because I can't actually see the window, if I hit down and then Enter, the system still functions as if I hit Enter on the first option.

Here's the code currently:
Code:
class Scene_AutoPilot

 

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

  # * Object Initialization

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

  def initialize(menu_index = 0)

    @menu_index = menu_index

  end

 

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

  # * Main

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

  def main

    # Make command window

    arr = [] # empty array

    arr << "Rabanastre" if $game_switches[4] == true...

    arr << "Dalmascan Westresands" if $game_switches[5] == true...

    arr << "Giza Plains" if $game_switches[6] == true...

    arr << "Ozmone Plain" if $game_switches[7] == true...

    arr << "Glabados Ruins" if $game_switches[8] == true...

    arr << "Jahara" if $game_switches[9] == true...

    arr << "The Ancient City of Giruvegan" if $game_switches[10] == true...

    arr << "The Feywood" if $game_switches[11] == true...

    arr << "Golmore Jungle" if $game_switches[12] == true...

    arr << "Eruyt Village" if $game_switches[13] == true...

    arr << "Paramina Rift" if $game_switches[14] == true...

    arr << "The Stillshrine of Miriam" if $game_switches[15] == true...

    arr << "Mt. Bur Omisace" if $game_switches[16] == true...

    arr << "Dalmascan Estresands" if $game_switches[17] == true...

    arr << "Nalbina Fortress" if $game_switches[18] == true...

    arr << "The Skycity of Bhujerba" if $game_switches[19] == true...

    arr << "Mosphoran Highwastes" if $game_switches[20] == true...

    arr << "The Salikawood" if $game_switches[21] == true...

    arr << "Phon Coast" if $game_switches[22] == true...

    arr << "Nabreus Deadland" if $game_switches[23] == true...

    arr << "The Necrohol of Nabudis" if $game_switches[24] == true...

    arr << "Tchita Uplands" if $game_switches[25] == true...

    arr << "Old Archades" if $game_switches[26] == true...

    arr << "Cerobi Steppe" if $game_switches[27] == true...

    arr << "Balfonheim Port" if $game_switches[28] == true...

    arr << "The Tomb of Raithwall" if $game_switches[29] == true...

    arr << "Ogir Yensa Sandsea" if $game_switches[30] == true...

    arr << "Nham Yensa Sandsea" if $game_switches[31] == true

    @command_window = Window_Command.new(160, arr)

    @command_window.index = @menu_index

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      break if $scene != self

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @command_window.dispose

  end

 

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

  # * Frame Update

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

  def update

    # Update windows

    @command_window.update

    # Call update_command

    update_command

  end

 

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

  # * Frame Update

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

  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)

      # Branch by command window cursor position

      case @command_window.index

      when 0  # Rabanastre

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Rabanastre

        $game_switches[101] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      when 1  # Giza Plains

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Go to Giza Plains

        $game_switches[102] = true

        $game_map.need_refresh = true

        # Close window

        $scene = Scene_Map.new

      return

    end

  end

end

end
 
Dude... XD i've put "...." as a filler, because i didn't know what to put.
You mustn't do that ! :)
Just type the condition you want to use :)

also :) because $game_switches value are either true of false, when you call them they will return that result... and the if executes if the expression (the condition ) is true... so basically you don't need to test the value of the switch to see if it's true or not :).
like this

if $game_switches[22] for example. if the switch is set to true, it'll execute.
.

Then the array might be empty, but that doesn't prevent your code from executing when you press C. ( in the update_command method)
Then because the array is filled differently, you can't test on the index position anymore, because as I said in my example, giza could be at the 1st place...
Instead you could test on the value at that index.

Also, you redoing the same code, ( only 1 line is different) between each block. That's bad coding, try to not write the same thing over and over... that's more time consuming for you.. and less readable in the end.

You can't see the window, because you forgot to put a transition when loading the scene. The screen is frozen when going from one scene to another (meaning stuff is drawn in a buffer and not displayed). Just had to apply the transition to display everything :)


Something like this will be better
[rgss] 
class Scene_AutoPilot
 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
 
  #--------------------------------------------------------------------------
  # * Main
  #--------------------------------------------------------------------------
  def main
    # Make command window
    arr = [] # empty array
    arr << "Rabanastre" if $game_switches[4]
    arr << "Dalmascan Westresands" if $game_switches[5]
    arr << "Giza Plains" if $game_switches[6]
    arr << "Ozmone Plain" if $game_switches[7]
    arr << "Glabados Ruins" if $game_switches[8]
    arr << "Jahara" if $game_switches[9]
    arr << "The Ancient City of Giruvegan" if $game_switches[10]
    arr << "The Feywood" if $game_switches[11]
    arr << "Golmore Jungle" if $game_switches[12]
    arr << "Eruyt Village" if $game_switches[13]
    arr << "Paramina Rift" if $game_switches[14]
    arr << "The Stillshrine of Miriam" if $game_switches[15]
    arr << "Mt. Bur Omisace" if $game_switches[16]
    arr << "Dalmascan Estresands" if $game_switches[17]
    arr << "Nalbina Fortress" if $game_switches[18]
    arr << "The Skycity of Bhujerba" if $game_switches[19]
    arr << "Mosphoran Highwastes" if $game_switches[20]
    arr << "The Salikawood" if $game_switches[21]
    arr << "Phon Coast" if $game_switches[22]
    arr << "Nabreus Deadland" if $game_switches[23]
    arr << "The Necrohol of Nabudis" if $game_switches[24]
    arr << "Tchita Uplands" if $game_switches[25]
    arr << "Old Archades" if $game_switches[26]
    arr << "Cerobi Steppe" if $game_switches[27]
    arr << "Balfonheim Port" if $game_switches[28]
    arr << "The Tomb of Raithwall" if $game_switches[29]
    arr << "Ogir Yensa Sandsea" if $game_switches[30]
    arr << "Nham Yensa Sandsea" if $game_switches[31]
   
    if arr.empty? # Put a default option, if the array is empty.
      arr << "No Location"
    end  
 
    @command_window = Window_Command.new(172, arr)
     
    if arr.first == "No Location" # Disable the option if it's the "No Location" one.    
      @command_window.draw_item(0, false) # that's the command to "dis
      @command_window.index = -1 # Hide the cursor
      @command_window.active = false # Deactivate the window, so we make sure the player can't use it!
    else
      @command_window.active = true # Just in case it's not activated by default  
      @command_window.index = @menu_index
    end
   
    Graphics.transition # THIS UNFREEZE the screen, and allow to draw the change :) That's why you couldn't see the window.
   
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      break if $scene != self
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @command_window.dispose
  end
 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # 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
 
    # Update windows
    @command_window.update
 
    # Call update_command
    update_command if @command_window.active # Now, the player can't access the C command if there'sn't any location available.
  end
 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update_command
   
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Branch by command window cursor value
      case @command_window.commands[@command_window.index] # Get the option at that index
      when "Rabanastre" # Use the location name instead
        # Go to Rabanastre
        $game_switches[101] = true
      when "Giza Plains"
        # Go to Giza Plains
        $game_switches[102] = true
      end
      $game_map.need_refresh = true
      # Close window
      $scene = Scene_Map.new
    end
  end
end
 
[/rgss]
 
You are amazing, trebor! I didn't know any of this. It took me a second, but I understand what you're saying now. It's much easier this way, and much more adaptable. Thanks for all of the help, man! Maybe I should just come to you with all of my scripting woes from now on XD

I owe you :3

EDIT: I have an undefined method error when I hit enter on any of the options. The line with the error:
Code:
case @command_window.commands[@command_window.index] # Get the option at that index

The error reads, "NoMethodError Occured. undefined method 'commands' for Window_Command."
 

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