[XP] Need help with my custom menu

Started by Ekusu, February 22, 2011, 01:30:42 pm

Previous topic - Next topic

Ekusu

Hi I am just a beginner in scripting (at least with Ruby and RGSS^^),
and Im working on a special menu for my game, but I got an error which I cant solve so if somebody could help me I would be happy.

Some information:

  • it uses background image

  • it hase has buttons not a command window

  • it's not complet jet^^

  • the comments are German in the script since I'm from Germany^^

  • if you have tips how i could do things better tell me it would be nice :^_^':



thats the message I get


Spoiler: ShowHide

#--------------------------------------------------------------
# CMS_Hauptfenster
#--------------------------------------------------------------

class CMS_Hauptfenster < Window_Base
# Erstellen des Fensters
     def initialize
      super(0, 0, 640, 480)
      self.contents = Bitmap.new(width - 32, height - 32)
      refresh
     end

     
#Bilder einblenden
     def refresh
       #Hintergrund einblenden
       @BG = Sprite.new
       @BG.bitmap = RPG::Cache.picture("Menu-BG") #öffnet das bild
       #Waffen einblenden
       @A1 = Sprite.new
       @A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #öffnet das bild
       @A1.x = 107 #x coordinate
       @A1.y = 480 #y coordinate
       #Skills einblenden
       @A2 = Sprite.new
       @A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #öffnet das bild
       @A2.x = 107 #x coordinate
       @A2.y = 520 #y coordinate
       #Items einblenden
       @A3 = Sprite.new
       @A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #öffnet das bild
       @A3.x = 107 #x coordinate
       @A3.y = 560 #y coordinate
       #Optionen einblenden
       @A4 = Sprite.new
       @A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #öffnet das bild
       @A4.x = 107 #x coordinate (ausgehend von der oberen linken ecke)
       @A4.y = 600 #y coordinate (ausgehend von der oberen linken ecke)
       
       @Auswahl = 1
     end
     
     def Auswahl
       if Auswahl > 4 then
         @Auswahl = 1
       elsif Auswahl < 0 then
         @Auswahl = 4
       end
       
       case Input.dir4
         when 2 then @Auswahl + 1
         when 6 then @Auswahl - 1
       end
         
       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)
        case Auswahl
          when 1 then
            return
          when 2 then
            return
          when 3 then
            return
          when 4 then
            return
        end
      end
     end
     
     def grafikupdate
       loop do
         case Auswahl
           when 1 then
           @A1.bitmap = RPG::Cache.picture("Menu-Waffen_A") #Ausgewählt
           @A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #nicht Ausgewählt
           @A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #nicht Ausgewählt
           @A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #nicht Ausgewählt
           when 2 then
           @A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #nicht Ausgewählt
           @A2.bitmap = RPG::Cache.picture("Menu-Skills_A") #Ausgewählt
           @A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #nicht Ausgewählt
           @A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #nicht Ausgewählt
           when 3 then
           @A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #nicht Ausgewählt
           @A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #nicht Ausgewählt
           @A3.bitmap = RPG::Cache.picture("Menu-Items_A") #Ausgewählt
           @A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #nicht Ausgewählt
           when 4 then
           @A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #nicht Ausgewählt
           @A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #nicht Ausgewählt
           @A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #nicht Ausgewählt
           @A4.bitmap = RPG::Cache.picture("Menu-Optionen_A") #Ausgewählt
         end
       end 
     end 
end

ForeverZer0

Because you are calling a scene that does not have a "main" method. All scenes have to have a main method. This how the game's main loop leeps the game going. See the "Main" script in the bottom of the editor. It is something like this:

while $scene != nil
  $scene.main
end


This means that the main method of a scene will always be called. The main method of the scene then calls its own updates, etc. in its own loop.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ekusu

February 22, 2011, 02:43:37 pm #2 Last Edit: February 22, 2011, 02:51:17 pm by Ekusu
Thx for the fast help^^

Ok now it won't crash if I press Esc

thats what I changed

# Erstellen des Fensters
    def initialize
     super(0, 0, 640, 480)
     self.contents = Bitmap.new(width - 32, height - 32)       
      #removed "refresh"
    end

   
#Bilder einblenden
    def main       #<changed
      #Hintergrund einblenden
      @BG = Sprite.new


but the script is hanging and only the window will be displayed

ForeverZer0

Because you need a loop in main, with an update method that actually makes the script do something.
My advice would be to go back and learn the bare essentials of RGSS before attempting to write a custom class.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ekusu

February 23, 2011, 12:37:04 pm #4 Last Edit: February 23, 2011, 05:08:59 pm by Ekusu
OK now I got it running completly.

Spoiler: ShowHide
#--------------------------------------------------------------
# CMS_Hauptfenster
#--------------------------------------------------------------

class CMS_Hauptfenster < Window_Base
 
 #--------------------------------------------------------------------------
 # * Starten
 #--------------------------------------------------------------------------
 def initialize()
   super(0, 0, 640, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.opacity = 0
 end
 
 #--------------------------------------------------------------------------
 # * Hauptprozess
 #--------------------------------------------------------------------------
 def main
   @auswahl = 0
   grafiken_laden    #Grafiken einblenden
   Graphics.transition    #Überblende

   #Hauptschleife
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   
   Graphics.freeze
   
   
 end

 #--------------------------------------------------------------------------
 #Grafiken einblenden
 #--------------------------------------------------------------------------
 def grafiken_laden
   @BG = Sprite.new
   @BG.bitmap = Bitmap.new("Graphics/Pictures/MBG") #öffnet das bild
   @BG.x = 320 - (@BG.bitmap.width / 2) #x coordinate
   @BG.x = 240 - (@BG.bitmap.height / 2) #y coordinate
   #Waffen einblenden
   @A1 = Sprite.new
   @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A")
   @A1.x = 0
   @A1.y = 335 - (@A1.bitmap.height / 2)
   #Skills einblenden
   @A2 = Sprite.new
   @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA")
   @A2.x = 0
   @A2.y = 375 - (@A2.bitmap.height / 2)
   #Items einblenden
   @A3 = Sprite.new
   @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA")
   @A3.x = 0
   @A3.y = 415 - (@A3.bitmap.height / 2)
   #Optionen einblenden
   @A4 = Sprite.new
   @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA")
   @A4.x = 0
   @A4.y = 455 - (@A4.bitmap.height / 2)
 end

 #--------------------------------------------------------------------------
 # * Auswahl, Menü schliesen, Auswahl bestätign
 #--------------------------------------------------------------------------
 def update
   #Steuerung
   if Input.trigger?(Input::UP) then
     $game_system.se_play($data_system.cursor_se)
     @auswahl -= 1
     if @auswahl < 0 then
       @auswahl = 4
     end
     grafikupdate
 end
 if Input.trigger?(Input::DOWN) then
     $game_system.se_play($data_system.cursor_se)
     @auswahl += 1
     if @auswahl > 4 then
       @auswahl = 0
     end
     grafikupdate
 end
   #Wenn Esc gedrückt wird
   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
 
   #Wenn Enter gedrückt wird
   if Input.trigger?(Input::C)
     case @auswahl
       when 1 then
         return
       when 2 then
         return
       when 3 then
         return
       when 4 then
         return
       end
     end
   end
   
 def grafikupdate
   case @auswahl
     when 0 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A") #Ausgewählt
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
     when 1 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_A") #Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
     when 2 then
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_A") #Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
     when 3 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_A") #Ausgewählt
   end
 end
end


Screen:
Spoiler: ShowHide

probably I will change the "buttons", they are too big^^

It's not ready yet because I don't have the other scripts ready.

But there is one thing that bothers me...
If I'm on the first option [@auswahl = 0] (Screenshot the yellow blade) I have to klick UP two times to get to option 4.
I have tried different ways, but it's allways the same.

SBR*

Quote from: Ekusu on February 23, 2011, 12:37:04 pm
Spoiler: ShowHide

OK now I got it running completly.

#--------------------------------------------------------------
# CMS_Hauptfenster
#--------------------------------------------------------------

class CMS_Hauptfenster < Window_Base
 
 #--------------------------------------------------------------------------
 # * Starten
 #--------------------------------------------------------------------------
 def initialize()
   super(0, 0, 640, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.opacity = 0
 end
 
 #--------------------------------------------------------------------------
 # * Hauptprozess
 #--------------------------------------------------------------------------
 def main
   @auswahl = 0
   grafiken_laden    #Grafiken einblenden
   Graphics.transition    #Überblende

   #Hauptschleife
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   
   Graphics.freeze
   
   
 end

 #--------------------------------------------------------------------------
 #Grafiken einblenden
 #--------------------------------------------------------------------------
 def grafiken_laden
   @BG = Sprite.new
   @BG.bitmap = Bitmap.new("Graphics/Pictures/MBG") #öffnet das bild
   @BG.x = 320 - (@BG.bitmap.width / 2) #x coordinate
   @BG.x = 240 - (@BG.bitmap.height / 2) #y coordinate
   #Waffen einblenden
   @A1 = Sprite.new
   @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A")
   @A1.x = 0
   @A1.y = 335 - (@A1.bitmap.height / 2)
   #Skills einblenden
   @A2 = Sprite.new
   @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA")
   @A2.x = 0
   @A2.y = 375 - (@A2.bitmap.height / 2)
   #Items einblenden
   @A3 = Sprite.new
   @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA")
   @A3.x = 0
   @A3.y = 415 - (@A3.bitmap.height / 2)
   #Optionen einblenden
   @A4 = Sprite.new
   @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA")
   @A4.x = 0
   @A4.y = 455 - (@A4.bitmap.height / 2)
 end

 #--------------------------------------------------------------------------
 # * Auswahl, Menü schliesen, Auswahl bestätign
 #--------------------------------------------------------------------------
 def update
   #Steuerung
   if Input.trigger?(Input::UP) then
     $game_system.se_play($data_system.cursor_se)
     @auswahl -= 1
     if @auswahl < 0 then
       @auswahl = 4
     end
     grafikupdate
 end
 if Input.trigger?(Input::DOWN) then
     $game_system.se_play($data_system.cursor_se)
     @auswahl += 1
     if @auswahl > 4 then
       @auswahl = 0
     end
     grafikupdate
 end
   #Wenn Esc gedrückt wird
   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
 
   #Wenn Enter gedrückt wird
   if Input.trigger?(Input::C)
     case @auswahl
       when 1 then
         return
       when 2 then
         return
       when 3 then
         return
       when 4 then
         return
       end
     end
   end
   
 def grafikupdate
   case @auswahl
     when 0 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A") #Ausgewählt
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
     when 1 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_A") #Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
     when 2 then
       @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_A") #Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
     when 3 then
       @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
       @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
       @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_A") #Ausgewählt
   end
 end
end


Screen:

probably I will change the "buttons", they are too big^^

It's not ready yet because I don't have the other scripts ready.

But there is one thing that bothers me...
If I'm on the first option [@auswahl = 0] (Screenshot) I have to klick UP two times to get to option 4.
I have tried different ways, but it's allways the same.



*Looks at the script*
*Gets confused*

I don't think you really understand. We commonly make the window and the scene different classes. You made them in one class.

Ekusu

I thought that too, but I was too lazy to do it right away, but now I have recovered a little and did it ^^

I hope there is nothing wrong AGAIN^^ but like I said I'm learning it
but I don't get the "error" which I got before, he is still ther

Window_Hauptfenster
Spoiler: ShowHide
#-------------------------------------------------------------------------------
# Window_Hauptfenster
#-------------------------------------------------------------------------------

class Window_Hauptfenster < Window_Base
 
  #-----------------------------------------------------------------------------
  # * Starten
  #-----------------------------------------------------------------------------
  def initialize()
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    grafiken_laden
  end

  #-----------------------------------------------------------------------------
  #Grafiken einblenden
  #-----------------------------------------------------------------------------
  def grafiken_laden
    @BG = Sprite.new
    @BG.bitmap = Bitmap.new("Graphics/Pictures/MBG") #öffnet das bild
    @BG.x = 320 - (@BG.bitmap.width / 2) #x coordinate
    @BG.x = 240 - (@BG.bitmap.height / 2) #y coordinate
    #Waffen einblenden
    @A1 = Sprite.new
    @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A")
    @A1.x = 0
    @A1.y = 335 - (@A1.bitmap.height / 2)
    #Skills einblenden
    @A2 = Sprite.new
    @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA")
    @A2.x = 0
    @A2.y = 375 - (@A2.bitmap.height / 2)
    #Items einblenden
    @A3 = Sprite.new
    @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA")
    @A3.x = 0
    @A3.y = 415 - (@A3.bitmap.height / 2)
    #Optionen einblenden
    @A4 = Sprite.new
    @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA")
    @A4.x = 0
    @A4.y = 455 - (@A4.bitmap.height / 2)
    grafikupdate
  end
 
  def grafikupdate
    case $hfauswahl
      when 0 then
        @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_A") #Ausgewählt
        @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
        @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
      when 1 then
        @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
        @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_A") #Ausgewählt
        @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
      when 2 then
        @A2.bitmap = Bitmap.new("Graphics/Pictures/Menu-Skills_nA") #nicht Ausgewählt
        @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_A") #Ausgewählt
        @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_nA") #nicht Ausgewählt
      when 3 then
        @A1.bitmap = Bitmap.new("Graphics/Pictures/Menu-Waffen_nA") #nicht Ausgewählt
        @A3.bitmap = Bitmap.new("Graphics/Pictures/Menu-Items_nA") #nicht Ausgewählt
        @A4.bitmap = Bitmap.new("Graphics/Pictures/Menu-Optionen_A") #Ausgewählt
    end
  end

end


Scene_CMS
Spoiler: ShowHide
#--------------------------------------------------------------
# Scene_CMS
#--------------------------------------------------------------

class Scene_CMS
 
  #--------------------------------------------------------------------------
  # * Starten
  #--------------------------------------------------------------------------
  def initialize(auswahl = 0)
    $hfauswahl = auswahl
  end
 
  #--------------------------------------------------------------------------
  # * Hauptprozess
  #--------------------------------------------------------------------------
  def main
    @hauptfenster = Window_Hauptfenster.new    #Grafiken einblenden
    Graphics.transition    #Überblende
    #Hauptschleife
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
   
    Graphics.freeze
   
   
  end

  #--------------------------------------------------------------------------
  # * Auswahl, Menü schliesen, Auswahl bestätign
  #--------------------------------------------------------------------------
  def update
    #Steuerung
    if Input.trigger?(Input::UP) then
      $game_system.se_play($data_system.cursor_se)
      $hfauswahl -= 1
      if $hfauswahl <= 0 then
        $hfauswahl = 4
      end
      @hauptfenster.grafikupdate
  end
  if Input.trigger?(Input::DOWN) then
      $game_system.se_play($data_system.cursor_se)
      $hfauswahl += 1
      if $hfauswahl > 4 then
        $hfauswahl = 0
      end
      @hauptfenster.grafikupdate
  end
    #Wenn Esc gedrückt wird
    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
 
    #Wenn Enter gedrückt wird
    if Input.trigger?(Input::C)
      case $hfauswahl
        when 1 then
          return
        when 2 then
          return
        when 3 then
          return
        when 4 then
          return
        end
      end
    end
     
 
end

Blizzard

Just a digression: Lol, you called it "Window_MainWindow". xD
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ekusu

February 23, 2011, 05:30:04 pm #8 Last Edit: February 23, 2011, 05:32:29 pm by Ekusu
yeah I know you understand german Blizzard xDD
I called it like that because the other windows will be like "subwindows" on the right site.
Maybe I will translate it in English later, since my game will be in english and german

Blizzard

Yeah, but Window_Main would have been kind of enough. Or maybe Window_MenuMain.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ekusu

when I startet that thing I caled it just "MenuMain" xDD

SBR*

I've found a bug.

We usually make the selections start at 0. You made the selections start at 1. There's nothing really wrong with that, as it wouldn't cause any errors, but in
if Input.trigger?(Input::DOWN)
, you set your $hfauswahl variable to 0 if it was 4, while the first selection is 1.

This doesn't solve your problem, BTW.

I've also found some minor problems. If you're using
if EXPRESSION
, you only need to add 'then' or ':' if you want to continue on the same line.

Secondly, instead of using
if Input.trigger?(KEY)
, you can also use
if Input.repeat?(KEY)
. Firstly, hold UP when using the current one, then test the second one and see the difference yourself :D.

There's one other problem, and I challenge you to find it, Ekusu :D.

Ekusu

If I start with 0, it somehow won't work, I don't know why -.-

The variable thing is solved, it works now^^

When it's like that?
if @a = 5 then @b = 10

That's good to know the input.repeat?^^

What kind of probleme is it?

Now I just need to know how I can equip weps and use items

and a question what is Graphics.freeze for
... ok i just googled it ^^


SBR*

Quote from: Ekusu on February 24, 2011, 06:49:28 am
Spoiler: ShowHide

If I start with 0, it somehow won't work, I don't know why -.-

The variable thing is solved, it works now^^

When it's like that?
if @a = 5 then @b = 10

That's good to know the input.repeat?^^

What kind of probleme is it?

Now I just need to know how I can equip weps and use items

and a question what is Graphics.freeze for
... ok i just googled it ^^




Beginnings of blocks of code commonly aren't defined explicit in Ruby. You can use
begin
  #BLOCK
end

, but you should only do this when absolutely necessary.

Cases when beginnings of blocks ARE defined explicit in Ruby are when using
do...end
or
{...}
, e.g. in
loop do
  #BLOCK
end


Conditional blocks' beginnings aren't defined explicit in Ruby. So you can just say:
if EXPRESSION
  #BLOCK
end


However, when you would like to write the executed code on the same line as the expression, you have to add 'then' or ':' betweeen the expression and the executed code, as Ruby would otherwise think that the executed code is part of the expression.

I hope this makes it clear to you :D.


Your first problem occured when you pressed UP. I solved a problem, which would occur when you pressed down.


Finally, I suggest you to take a look at Window_Select and Window_Command and look how they are built up. It should help you a lot.


Good luck :D!

ForeverZer0

@b = 10 if @a == 5


That is much easier to do than a "then" or ":"
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

SBR*

Quote from: ForeverZer0 on February 24, 2011, 12:20:06 pm
@b = 10 if @a == 5


That is much easier to do than a "then" or ":"


There may be situations when
if EXPRESSION : EXECUTE end
is clearer, but I'm not sure at all.

Ekusu

Ok I have done some stuff

Viewport_Hauptfenster
Spoiler: ShowHide
#-------------------------------------------------------------------------------
# Window_Hauptfenster
#-------------------------------------------------------------------------------

class Viewport_Hauptfenster < Viewport

def initialize()
@viewport1 = Viewport.new(0, 0, 640, 480)
grafiken_laden
end


#-----------------------------------------------------------------------------
#Grafiken einblenden
#-----------------------------------------------------------------------------
def grafiken_laden
@BG = Sprite.new
@BG.bitmap = RPG::Cache.picture("MBG") #öffnet das bild
@BG.x = 320 - (@BG.bitmap.width / 2) #x coordinate
@BG.y = 240 - (@BG.bitmap.height / 2) #y coordinate
#Waffen einblenden
@A1 = Sprite.new
@A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA")
@A1.x = 0
@A1.y = 335 - (@A1.bitmap.height / 2)
#Skills einblenden
@A2 = Sprite.new
@A2.bitmap = RPG::Cache.picture("Menu-Skills_nA")
@A2.x = 0
@A2.y = 375 - (@A2.bitmap.height / 2)
#Items einblenden
@A3 = Sprite.new
@A3.bitmap = RPG::Cache.picture("Menu-Items_nA")
@A3.x = 0
@A3.y = 415 - (@A3.bitmap.height / 2)
#Optionen einblenden
@A4 = Sprite.new
@A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA")
@A4.x = 0
@A4.y = 455 - (@A4.bitmap.height / 2)
grafikupdate
end

def grafikupdate
case $hfauswahl
when 0 then
@A1.bitmap = RPG::Cache.picture("Menu-Waffen_A") #Ausgewählt
@A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #nicht Ausgewählt
@A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #nicht Ausgewählt
when 1 then
@A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #nicht Ausgewählt
@A2.bitmap = RPG::Cache.picture("Menu-Skills_A") #Ausgewählt
@A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #nicht Ausgewählt
when 2 then
@A2.bitmap = RPG::Cache.picture("Menu-Skills_nA") #nicht Ausgewählt
@A3.bitmap = RPG::Cache.picture("Menu-Items_A") #Ausgewählt
@A4.bitmap = RPG::Cache.picture("Menu-Optionen_nA") #nicht Ausgewählt
when 3 then
@A1.bitmap = RPG::Cache.picture("Menu-Waffen_nA") #nicht Ausgewählt
@A3.bitmap = RPG::Cache.picture("Menu-Items_nA") #nicht Ausgewählt
@A4.bitmap = RPG::Cache.picture("Menu-Optionen_A") #Ausgewählt
end
end

end

Scene_CMS
Spoiler: ShowHide
[ruby]#--------------------------------------------------------------
# Scene_CMS
#--------------------------------------------------------------

class Scene_CMS

#--------------------------------------------------------------------------
# * Starten
#--------------------------------------------------------------------------
def initialize(auswahl = 0)
$hfauswahl = auswahl

end

#--------------------------------------------------------------------------
# * Hauptprozess
#--------------------------------------------------------------------------
def main
@hauptfenster = Viewport_Hauptfenster.new #Grafiken einblenden
Graphics.transition #Überblende
#Hauptschleife
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end

Graphics.freeze

end

#--------------------------------------------------------------------------
# * Auswahl, Menü schliesen, Auswahl bestätign
#--------------------------------------------------------------------------
def update
#Steuerung
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
$hfauswahl -= 1
wait(5)
hauptfenster_update
end
if Input.repeat?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
$hfauswahl += 1
wait(5)
hauptfenster_update
end
#Wenn Esc gedrückt wird
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

#Wenn Enter gedrückt wird
if Input.trigger?(Input::C)
case $hfauswahl
when 0 then
$game_system.se_play($data_system.decision_se)
$scene = Scene_Waffen1.new
return
when 1 then
return
when 2 then
return
when 3 then
return
end
end
end

def hauptfenster_update
$hfauswahl %= 4
@hauptfenster.grafikupdate
end
end[/ruby]

Viewport_Waffen1
Spoiler: ShowHide
[ruby]#-------------------------------------------------------------------------------
# Viewport_Waffen1
#-------------------------------------------------------------------------------

class Viewport_Waffen1 < Viewport

def initialize()
@viewport1 = Viewport.new(320, 240, 640, 480)
grafiken_laden
end

#-----------------------------------------------------------------------------
#Grafiken einblenden
#-----------------------------------------------------------------------------
def grafiken_laden
# Hintergrund
@BG = Sprite.new
@BG.bitmap = RPG::Cache.picture("W-M-BG") #öffnet das bild
@BG.x = 178 #x coordinate
@BG.y = 82 #y coordinate
# Charanzeige
@C = Sprite.new
@C.bitmap = RPG::Cache.picture("WP-C_1") #öffnet das bild
@C.x = 412 - (@C.bitmap.width / 2) #x coordinate
@C.y = 91 - (@C.bitmap.height / 2) #y coordinate
# Auswahl 1
@B1 = Sprite.new
@B1.bitmap = RPG::Cache.picture("W1-B1_A") #öffnet das bild
@B1.x = 240 - (@B1.bitmap.width / 2) #x coordinate
@B1.y = 162 - (@B1.bitmap.height / 2) #y coordinate
# Auswahl 2
@B2 = Sprite.new
@B2.bitmap = RPG::Cache.picture("W1-B2_nA") #öffnet das bild
@B2.x = 240 - (@B2.bitmap.width / 2) #x coordinate
@B2.y = 250 - (@B2.bitmap.height / 2) #y coordinate
# Auswahl 3
@B3 = Sprite.new
@B3.bitmap = RPG::Cache.picture("W1-B3_nA") #öffnet das bild
@B3.x = 240 - (@B3.bitmap.width / 2) #x coordinate
@B3.y = 338 - (@B3.bitmap.height / 2) #y coordinate
# Auswahl 4
@B4 = Sprite.new
@B4.bitmap = RPG::Cache.picture("W1-B4_nA") #öffnet das bild
@B4.x = 240 - (@B4.bitmap.width / 2) #x coordinate
@B4.y = 426 - (@B4.bitmap.height / 2) #y coordinate
end

def grafikupdate
case $waffe
when 0 then
@B1.bitmap = RPG::Cache.picture("W1-B1_A")
@B2.bitmap = RPG::Cache.picture("W1-B2_nA")
@B4.bitmap = RPG::Cache.picture("W1-B4_nA")
when 1 then
@B1.bitmap = RPG::Cache.picture("W1-B1_nA")
@B2.bitmap = RPG::Cache.picture("W1-B2_A")
@B3.bitmap = RPG::Cache.picture("W1-B3_nA")
when 2 then
@B2.bitmap = RPG::Cache.picture("W1-B2_nA")
@B3.bitmap = RPG::Cache.picture("W1-B3_A")
@B4.bitmap = RPG::Cache.picture("W1-B4_nA")
when 3 then
@B1.bitmap = RPG::Cache.picture("W1-B1_nA")
@B3.bitmap = RPG::Cache.picture("W1-B3_nA")
@B4.bitmap = RPG::Cache.picture("W1-B4_A")
end
end

def waffe

end

end

Scene_Waffen1
Spoiler: ShowHide
#--------------------------------------------------------------
# Scene_Waffen1
#--------------------------------------------------------------

class Scene_Waffen1

#--------------------------------------------------------------------------
# * Starten
#--------------------------------------------------------------------------
def initialize(waffe = 0)
$waffe = waffe
end

#--------------------------------------------------------------------------
# * Hauptprozess
#--------------------------------------------------------------------------
def main
@waffen = Viewport_Waffen1.new #Grafiken einblenden
Graphics.transition #Überblende
#Hauptschleife
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end

Graphics.freeze

end

#--------------------------------------------------------------------------
# * Auswahl, Menü schliesen, Auswahl bestätign
#--------------------------------------------------------------------------
def update
#Steuerung
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
$waffe -= 1
waffen_update
wait(5)
end
if Input.repeat?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
$waffe += 1
waffen_update
wait(5)
end
if Input.trigger?(Input::RIGHT)
@CP = Sprite.new
@CP.bitmap = RPG::Cache.picture("WP-C_R") #öffnet das bild
@CP.x = 569 - (@CP.bitmap.width / 2) #x coordinate
@CP.y = 92 - (@CP.bitmap.height / 2) #y coordinate
Audio.se_play("Audio/SE/033-Switch02", 100, 125)
wait(2)
@CP.dispose
wait(1)
$scene = Scene_Waffen2.new
end
if Input.trigger?(Input::LEFT)
@CP = Sprite.new
@CP.bitmap = RPG::Cache.picture("WP-C_L") #öffnet das bild
@CP.x = 256 - (@CP.bitmap.width / 2) #x coordinate
@CP.y = 92 - (@CP.bitmap.height / 2) #y coordinate
Audio.se_play("Audio/SE/033-Switch02", 100, 125)
wait(2)
@CP.dispose
wait(1)
$scene = Scene_Waffen4.new
end

#Wenn Esc gedrückt wird
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_CMS.new(0)
return
end

#Wenn Enter gedrückt wird
if Input.trigger?(Input::C)
case $waffe
when 0 then
$game_system.se_play($data_system.equip_se)

return
when 1 then
$game_system.se_play($data_system.equip_se)

return
when 2 then
$game_system.se_play($data_system.equip_se)

return
when 3 then
$game_system.se_play($data_system.equip_se)

return
end
end
end

def waffen_update
$waffe %= 4
@waffen.grafikupdate
end


end


now the question if Ipres left or right in Scene_Waffen1 (-4) the old graphics don't disapear so it looks ugly and its probably not good