Sujet n°11958
Posté par Xyrram le 24 Aoû - 13:52 (2012)
Titre : 2 ereurs tres embetantes
Bon voila j'apprend le rubis et j'ai donc decider de créé un anuaire comme premier script.
Mais un probleme se pose au lancement de l'anuaire via le menu;
Code:

#==============================================================================
# ■ Anuaire
# Pokemon SoulDarkness DS - DragonStarX45
# 23/08/12
#------------------------------------------------------------------------------
class ANUAIRE< Window_Base
  include POKEMON_S
 
   def initialize
    super(0, 200, 480, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = $fontsize
    @commands = ["Personages principaux", "Personages secondaire", "Quitter"]
    @item_max = @commands.size
    @column_max = 3
    refresh # Appelle de la méthode "refresh"
    self.index = 0
  end # Fin de la méthode
  def refresh
     self.contents.clear
     # Boucle pour afficher chaque commande
     for i in 0...@item_max
       # Position X selon i
      x = 4 + i * 160
      # Taille du texte
      text_size = self.contents.text_size(@commands[i]).width
      # Affichage du texte.
     self.contents.draw_text(x, 0, text_size, 32, @commands[i])
  end
 end   
end

Voila l'erreur

il y a aussi un souci avec pokemon menu*
Voila le code
Code:

#==============================================================================
# ■ Pokemon_Menu
# Pokemon Script Project - Krosk
# 18/07/07
# 22/02/10 - Palbolsky
#-----------------------------------------------------------------------------
# Scène modifiable
#-----------------------------------------------------------------------------
# Menu principal accessible par échap
#-----------------------------------------------------------------------------

module POKEMON_S
  class Pokemon_Menu < Window_Base
    #--------------------------------------------------------------------------
    #
    #--------------------------------------------------------------------------
    def initialize(menu_index = 0)
      @menu_index = menu_index
      super(0,0,640,480)
      self.contents = Bitmap.new(width - 32, height - 32)     
      self.opacity = 0     
      self.z = 11     
    end     
    #--------------------------------------------------------------------------
    #
    #--------------------------------------------------------------------------
    def main
      @spriteset = Spriteset_Map.new
      @interface = Interface_Echap.new
     
      if POKEMON_S::VIEWER_TEAM
        @pkmn_team = Pokemon_Equipe.new
      end       
     
      s1 = "POKéDEX"
      s3 = "POKéMON"
      s5 = "SAC"
      s7 = "ANUAIRE"
      s2 = Player.name
      s4 = "SAUVER"
      s6 = "OPTIONS"
      s8 = "QUITTER"
      s9 = "Anuaire"
     
      @command_window = Window_Command.new(80, [s1, s2, s3, s4, s5, s6, s7, s9], $fontsizebig, 2, 14)     
      @command_window.index = @menu_index
      @command_window.x = 480 - 169 - 123 + 200
      @command_window.y = 28 - 20
      @command_window.z = 10000
      @command_window.visible = false
     
      @selecteur = Sprite.new
      @selecteur.z = 200
      if $color_menu == 1 or $color_menu == nil # Vert
        @string = "_rouge"     
      elsif $color_menu == 0 # Bleu
        @string = "_vert"
      elsif $color_menu == 2 # Rouge
        @string = "_bleu"
      end
      @selecteur.bitmap = RPG::Cache.picture("Menu Echap/selector_menu" + @string)                       
   
      if @command_window.index == 0
        @selecteur.x = 37
        @selecteur.y = 249     
      elsif @command_window.index == 2
        @selecteur.x = 37
        @selecteur.y = 289
      elsif @command_window.index == 4
        @selecteur.x = 37
        @selecteur.y = 329
      elsif @command_window.index == 6
        @selecteur.x = 37
        @selecteur.y = 369
      end
     
      if @command_window.index == 1
        @selecteur.x = 117
        @selecteur.y = 249
      elsif @command_window.index == 3
        @selecteur.x = 117
        @selecteur.y = 289
      elsif @command_window.index == 5
        @selecteur.x = 117
        @selecteur.y = 329
      elsif @command_window.index == 9
        @selecteur.x = 117
        @selecteur.y = 369   
      end     
     
      if $pokemon_party.size == 0
        # Enlève accès Equipe
        @command_window.disable_item(2)
      end
      if not($data_pokedex[0])
        # Enlève accès Pokédex si non possédé
        @command_window.disable_item(0)
      end
      if $game_system.save_disabled
        @command_window.disable_item(5)
      end         
     
      @command_window.disable_item(5)     
         
      Graphics.transition
      loop do             
        Graphics.update
        Input.update
        update
        if $scene != self
          break
        end
      end   
      Graphics.freeze       
      @command_window.dispose
      @spriteset.dispose
      @selecteur.dispose       
      @interface.dispose             
      @pkmn_team.dispose if not @pkmn_team.nil?
      Graphics.freeze
    end   
    #--------------------------------------------------------------------------
    #
    #--------------------------------------------------------------------------
    def update
      if @command_window.index == 0
        @selecteur.x = 37
        @selecteur.y = 249     
      elsif @command_window.index == 2
        @selecteur.x = 37
        @selecteur.y = 289
      elsif @command_window.index == 4
        @selecteur.x = 37
        @selecteur.y = 329
      elsif @command_window.index == 6
        @selecteur.x = 37
        @selecteur.y = 369
      elsif @command_window.index == 1
        @selecteur.x = 117
        @selecteur.y = 249
      elsif @command_window.index == 3
        @selecteur.x = 117
        @selecteur.y = 289
      elsif @command_window.index == 5
        @selecteur.x = 117
        @selecteur.y = 329
       elsif @command_window.index == 9
        @selecteur.x = 117
        @selecteur.y = 369 
      end           
     
      # ウィンドウを更新     
      @command_window.update
      @spriteset.update
      @selecteur.update
      @interface.update     
      # コマンドウィンドウがアクティブの場合: update_command を呼ぶ
      if @command_window.active
        update_command
        return
      end
    end
   
    def dispose
      super
    end
     
    #--------------------------------------------------------------------------
    # ● フレーム更新 (コマンドウィンドウがアクティブの場合)
    #--------------------------------------------------------------------------
    def update_command           
      # B ボタンが押された場合
      if Input.trigger?(Input::B)
        # キャンセル SE を演奏
        $game_system.se_play($data_system.cancel_se)
        # マップ画面に切り替え       
        $scene = Scene_Map.new
        self.contents.clear
        return       
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)         
        # パーティ人数が 0 人で、セーブ、ゲーム終了以外のコマンドの場合
        if $game_party.actors.size == 0 and @command_window.index < 4
          # ブザー SE を演奏
          $game_system.se_play($data_system.buzzer_se)
          return         
        end
        # コマンドウィンドウのカーソル位置で分岐
        case @command_window.index         
        when 0 # Pokédex         
          if not($data_pokedex[0])
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          $game_system.se_play($data_system.decision_se)
          $scene = Pokemon_Pokedex.new
          self.contents.clear
        when 2 # Menu
          if $pokemon_party.size == 0
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          $game_system.se_play($data_system.decision_se)
          $scene = Pokemon_Party_Menu.new
        when 4 # Sac
          $game_system.se_play($data_system.decision_se)
          $scene = Pokemon_Item_Bag.new
        when 6 # Pokématos
          if $game_switches[9] == false
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          $game_system.se_play($data_system.decision_se)
          $scene = Pokematos.new     
        when 1 # Carte dresseur
          $game_system.se_play($data_system.decision_se)
          $game_temp.common_event_id = 19
          $scene = Scene_Map.new           
        when 3 # Sauvegarde
          if $game_system.save_disabled
            $game_system.se_play($data_system.buzzer_se)
            return           
          end
          $game_system.se_play($data_system.decision_se)
          $scene = Pokemon_Save.new
          self.contents.clear
        when 5 # OPTIONS
          $game_system.se_play($data_system.decision_se)
          $scene = OPTION.new
            end
          return
        when 9 # ANNUAIRE
          $game_system.se_play($data_system.decision_se)
          $scene = ANUAIRE.new
            end
          return
      end
    end
  end
end

L'erreure est une sytaxe error a la ligne 233
Merci a toute personne pourvant m'aider (une place dans les credits sera bien sur attribuer)

Posté par Opale le 24 Aoû - 13:58 (2012)
Pour ton deuxième problème, je pense que ton code devrais s'écrire comme ça à la fin :
Code:
        when 5 # OPTIONS 
          $game_system.se_play($data_system.decision_se)   
          $scene = OPTION.new 
          return   
        when 9 # ANNUAIRE 
          $game_system.se_play($data_system.decision_se)   
          $scene = ANUAIRE.new 
             
          return 
        end
      end 
    end 
  end 
end 

Posté par Xyrram le 24 Aoû - 14:00 (2012)
Je verifie et je te le dit
EDIT:J'ai tester et sa marche mais le selecteur ne va pas j'usqu'a l'option et je ne peut donc pas choisir l'anuaire

Posté par Khayle le 24 Aoû - 19:18 (2012)
Opale a écrit:
Pour ton deuxième problème, je pense que ton code devrais s'écrire comme ça à la fin :
Code:
        when 5 # OPTIONS 
          $game_system.se_play($data_system.decision_se)   
          $scene = OPTION.new 
          return   
        end   
        when 9 # ANNUAIRE 
          $game_system.se_play($data_system.decision_se)   
          $scene = ANUAIRE.new 
             
          return 
        end
      end 
    end 
  end 
end 


Il manquait un end après le return du #5.

Posté par Xyrram le 24 Aoû - 20:52 (2012)
Ban justement le end fait beuger(ah ok après le return) je teste des que je suis chez moi et je te prévient du résultat (et pour mon annuaire tu a trouve l'erreur )

Posté par Elric le 24 Aoû - 21:23 (2012)
pour ton problème d'index essaye ça :

Code:

def initialize(index = 0)
  @index = index
  #... suite de ton script


Pour ton annuaire, c'est tout sauf une $scene ! Pour une scene, il faut une def main :
Code:

def main
  Graphics.transition
  loop do
    Graphics.update
    Input.update
    update
    while $scene != self
      break
    end
  end
  Graphics.freeze
  dispose # Si tu as une def dispose après
  Graphics.freeze
end


La base de la $scene c'est ça !

Posté par Nuri Yuri le 25 Aoû - 08:11 (2012)
N'oublies pas de mettre attr_accessor :index avant def initialize pour pouvoir utiliser self.index=(value).
Le code d'Opal est bon, y'avais juste un end en trop Gros matou qui ronronne

Posté par Elric le 25 Aoû - 11:52 (2012)
Bonne remarque, merci Nyuki !

EDIT : Trouvé le problème !

Il n'y a pas de when 8 dans case et pas de @command_window.index = 8 !

Parce que si c'est s9 (base 1) il devient 8 (base 0) !

Posté par Xyrram le 25 Aoû - 15:30 (2012)
J'ai pas saisi ou faut que je mette le déf initialize index
Et je replace tout les 9 par des 8?
Aussi que devrais je mettre si ce n'est pas une scène ?
Désoler de toute ces questions

Posté par Elric le 25 Aoû - 20:23 (2012)
1- D'abord, tu fais ça :
Code:

class ANUAIRE
  attr_accessor :index
  def initialize(index = 0)
    @index = index
    @fond = Sprite.new
    @fond.bitmap = RPG::Cache.picture("nom_de_limage.png") # Faut bien que ton annuaire ait un fond !
    # Suite du script... Tu enlèves refresh.


2- Ensuite, tu mets la def main que je t'ai donnée plus haut :
Code:

    def main 
      Graphics.transition 
      loop do 
        Graphics.update 
        Input.update 
        update 
        while $scene != self 
          break 
        end 
      end 
      Graphics.freeze 
      dispose # Si tu as une def dispose après 
      Graphics.freeze 
    end


3- Tu remplaces def refresh par def update et tu nrajoutes ça :
Code:

  @command.update
  @item_max.update
  @column_max.update


4- tu rajoutes ça :
Code:

def dispose
  @command.dispose
  @item_max.dispose
  @column_max.dispose
end


5- Tu l'appelles comme ça :
Code:
$scene = ANUAIRE.new


===============================

Pour le menu, change tous les "9" (sauf les "s9") par des "8".

Posté par Xyrram le 25 Aoû - 20:47 (2012)
Pour def refresh je l'efface carement ou je renome refresh par uptade?

Posté par Elric le 26 Aoû - 00:46 (2012)
Tu renommes seulement.

Posté par Xyrram le 28 Aoû - 15:06 (2012)
Bon sa a fonctioner mais j'ai une autre erreure maintenant