Sujet n°11441
Posté par Whurio le 4 Mai - 23:43 (2012)
Titre : Problème création système noigrume
Salut à tous,

je suis en train d'essayer de créer un script de gestion des noigrumes en m'inspirant du système de baies présent dans le jeu.
J'ai beau me creuser les méninges, il m'indique une erreur.
L'erreur survient une fois sur la carte qui initialise l'arbre (init_noigrume())

Voici le log :

Spoiler
---------- Erreur de script : Interpreter Bis ----------
----- Type
NoMethodError

----- Message
- ARGS - [4, []]
Section188:112:in `init_noigrume'undefined method `[]=' for nil:NilClass

----- Position dans Interpreter Bis
Ligne 445

----- Backtrace
Script : Interpreter Bis | Ligne : 445 | Méthode : in `command_355'
Script : Loading | Ligne : 1 | Méthode : in `command_355'
Script : Interpreter 2 | Ligne : 215 | Méthode : in `eval'
Script : Interpreter Bis | Ligne : 445 | Méthode : in `command_355'
Script : Interpreter 2 | Ligne : 215 | Méthode : in `execute_command'
Script : Interpreter 1 | Ligne : 199 | Méthode : in `update'
Script : Interpreter 1 | Ligne : 113 | Méthode : in `loop'
Script : Interpreter 1 | Ligne : 204 | Méthode : in `update'
Script : Scene_Map | Ligne : 51 | Méthode : in `alias_update'
Script : Scene_Map | Ligne : 48 | Méthode : in `loop'
Script : Scene_Map | Ligne : 67 | Méthode : in `alias_update'
Script : MAPPANEL | Ligne : 90 | Méthode : in `old_update'
Script : TempsJourNuit | Ligne : 248 | Méthode : in `update_passminimap'
Script : Minimap | Ligne : 44 | Méthode : in `update'
Script : Scene_Map | Ligne : 25 | Méthode : in `old_main'
Script : Scene_Map | Ligne : 19 | Méthode : in `loop'
Script : Scene_Map | Ligne : 30 | Méthode : in `old_main'
Script : TempsJourNuit | Ligne : 237 | Méthode : in `main_passminimap'
Script : Minimap | Ligne : 31 | Méthode : in `main'
Script : Main | Ligne : 49


Voici le code de ma classe :

Spoiler
# Temps à attendre pour nouveau fruit
TPS_NEW = [24, 0, 0]

# {"TYPE" => [id]}
NOIGUME = {
        #"BAIE CERIZ"  => [ 1, [12, 0, 0],  5,  3],
        "BLANCHE"  => [ 1 ],
        "BLEU"  => [2],
        "JAUNE" => [3],
        "NOIRE" => [4],
        "ROSE"  => [5],
        "ROUGE" => [6],
        "VERT"  => [7],
       }

class Noigrume
  attr_accessor :type
  attr_accessor :id_type
  attr_accessor :id_noigrume
  attr_accessor :date
  attr_accessor :temps
  attr_accessor :dt_st_sv
  attr_accessor :pret
  def initialize(type)
    clock     = Time.now
    @type     = type
    @id_type  = NOIGRUME[@type][0]
    @id_noigrume = $id_noigrume
    $id_noigrume  = 0
    @pret = 1
    @date     = [$game_variables[99],clock.hour,clock.min,clock.sec]
    @temps    = TPS_NEW
    tps = @temps[0] * 3600
    tps += @temps[1] * 60
    tps += @temps[2]
    tps = tps.to_i
    @dt_st_sv = [
                 @date[0] + tps / 86400,
                 @date[1] + (tps % 86400) / 3600,
                 @date[2] + (tps % 3600) / 60,
                 @date[3] + tps % 60
                ]
  end
 
  def maj
    clock = Time.new
    date = [$game_variables[99],clock.hour,clock.min,clock.sec]
    for i in 0..3
      if date[i] > @dt_st_sv[i]
        retour = true
        break
      elsif date[i] == @dt_st_sv[i]
        next
      else
        retour = false
        break
      end
    end
    if retour
      if @stade <= 3
        @temps    = BAIE[type][1]
        for i in 0...@temps.size
          @temps[i] *= TPS_STADES[@stade] / 100.0
        end
        tps = @temps[0] * 3600
        tps += @temps[1] * 60
        tps += @temps[2]
        tps = tps.to_i
        date = [$game_variables[99],clock.hour,clock.min,clock.sec]
        @dt_st_sv = [
                     date[0] + tps / 86400,
                     date[1] + (tps % 86400) / 3600,
                     date[2] + (tps % 3600) / 60,
                     date[3] + tps % 60
                    ]
      end
    end
  end
end 

class Game_Map
  alias noigrume_refresh refresh
  def refresh
    if @map_id > 0
      noigrume_refresh
      if not(@events.empty?) and $game_variables[5000].type == Hash and $game_variables[5000]["noigrume"] != nil and $game_variables[5000]["noigrume"][@map_id] != nil
        for i in @events.keys
          if $game_variables[5000]["noigrume"][@map_id][i] != nil
              maj_noigrume
              @events[i].character_name = "noigrumiers.png"
              @events[i].direction = 2 * stade
          end
        end
      end
    end
  end
 
  def maj_noigrume
    for i in 1..@events.size
      if $game_variables[5000]["noigrume"][@map_id][i] != nil
        $game_variables[5000]["noigrume"][@map_id][i].maj
      end
    end
  end
end
 
class Interpreter

  #Numéro carte,numéro événement,type noigrume
  def init_noigrume(map = $game_map.map_id, no_arbre = @event_id, noigrume = "BLANCHE")
    $noigrume_id = Item.id(noigrume)
    $game_variables[5000]["noigrume"][map] = []
    $game_variables[5000]["noigrume"][map][event] = Noigrume.new(noigrume)
  end
end


Désolé si cette question peut paraitre idiote,je débute en ruby.