🤔 Para Refletir :
"O segredo para desenvolver ótimos jogos é... ahm... bom, se eu contasse, não seria mais segredo."
- Jazz

(RESOLVIDO)nil:NilClass error

KAI GAMES Masculino

Plebeu
Membro
Membro
Juntou-se
06 de Fevereiro de 2019
Postagens
24
Bravecoins
31
olá!, estou utilizando um script de ATB(batalha em tempo real criado pelo XRXS e  modificado pelo herectic) crédito a eles:

cSWZYXD.png


porém ao iniciar o projeto recebo este erro:

wGf4hYv.png


existe alguma forma de definir este método no própio script em questão?

ja burlei esse erro algumas vezes  trocando  posição de scripts e mudando algumas linhas  mas queria realmente saber qual é o motivo disso ocorer

abaixo está o script e  a linha onde se encontra o erro:

Código:
#==============================================================================
#                                                                             #
#      Heretic's Overhaul of the XRXS ATB Battle System                       #
#      Version: 1.032                                                         #
#      Updated: Friday, April 3rd, 2015                                       #
#                                                                             #
#==============================================================================


#==============================================================================
# ** Scene_Battle_CP - Count Progress (or Constipated Platypus?)
#----------------------------------------------------------------------------
#
#    This class gives each Battler (Actors and Enemies), a property called CP.
#
#    Each Battlers CP will accumulate until it is Full.  When the Battler's
#    CP is full, they are allowed to perform an Action.
#
#    CP is a Range between 0 and 65535
#
#    Different Actions can cost different ammounts of CP.
#
#    The CP Bar that shows how much CP an Actor has is handled in the
#    the ATB - Window_CP Script.
#
#==============================================================================
class Scene_Battle_CP
  #----------------------------------------------------------------------------
  # * Initialize Thread
  #----------------------------------------------------------------------------
  def initialize
    # Create an empty Array for All Battlers
    @battlers = []
    # Add all Actors to array
    for actor in $game_party.actors
	    @battlers.push(actor)
    end    
    # Add all Enemies to array
    for enemy in $game_troop.enemies
	    @battlers.push(enemy)
    end
    # Determine Agility Total of all Movable Battlers (not Hidden)
    @agi_total = total_agility
    # If Random CP is Allowed - Demo or Tutorials
    if not $no_random_cp
      # If Suprise Attack
      if $game_temp.suprise_attack
        # Set CP based on who suprised who
        set_suprise_cp
      # No Suprise Attack
      else
        # Set Initial CP with slightly Random Values
        for battler in @battlers
          # Party Size
          size = $game_party.actors.size
          # Randomize Initial CP
          new_cp = 65535*(rand(85)+15)/250 * battler.agi/@agi_total*size
          # Clamp Values to 0 - 65535
          battler.cp = [[new_cp,0].max,65535].min          
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Return Version Number
  #
  # This is used to check for the modifications this script makes available
  #
  #--------------------------------------------------------------------------  
  def scene_battle_cp_version
    return 1.03
  end    
  #----------------------------------------------------------------------------
  # * Start - Battlers start accumulating CP
  #----------------------------------------------------------------------------
  def start
    if @cp_thread != nil
	    return
    end
    @cancel = false
    # Create a parallel CP Thread
    @cp_thread = Thread.new do
	    while @cancel != true
	      self.update
	      sleep(0.05)
      end
    end
  end
  #----------------------------------------------------------------------------
  # * Stop - Battlers stop accumulating CP
  #----------------------------------------------------------------------------
  def stop
    @cancel = true
    if @cp_thread != nil
	    @cp_thread.join
	    @cp_thread = nil
    end
  end
  #----------------------------------------------------------------------------
  # * Total Agility
  #----------------------------------------------------------------------------
  def total_agility
    agility_sum = 0
    # Get Agility from Each Battler
    for battler in @battlers
      # Exclude Dead, Hidden, and Immovable Battlers
      if not battler.dead? and battler.movable?
        # Add Battlers Agility to Agility Total
        agility_sum += battler.agi
      end
    end
    # Prevent Division by Zero Error
    agility_sum = 1 if agility_sum == 0
    # Return Value
    return agility_sum
  end
  #----------------------------------------------------------------------------
  # * Set Suprise CP - Same Logic as Escape
  #----------------------------------------------------------------------------
  def set_suprise_cp
    # Calculate enemy agility average
    enemies_agi = 0
    enemies_number = 0
    for enemy in $game_troop.enemies
      if enemy.exist?
        enemies_agi += enemy.agi
        enemies_number += 1
      end
    end
    if enemies_number > 0
      enemies_agi /= enemies_number
    end
    # Calculate actor agility average
    actors_agi = 0
    actors_number = 0
    for actor in $game_party.actors
      if actor.exist?
        actors_agi += actor.agi
        actors_number += 1
      end
    end
    # Prevent division by zero
    if actors_number > 0
      actors_agi /= actors_number
    end
    # Prevent Division by Zero (when NO enemies are in Troop)
    if enemies_agi > 0
      # If Actors Suprised Enemy
      if $game_temp.suprise_attack == 1
        # Chance of Success for Actors
        success = rand(100) < 50 * actors_agi / enemies_agi
        # If Successful on Suprise Attack
        if success
          # Set Actors to Max CP
          for actor in $game_party.actors
            actor.cp = 65534.9
          end
          # Set Enemies to Zero CP
          for enemy in $game_troop.enemies
            enemy.cp = 0
          end
        # Not a Successful Suprise attack
        else
          # Reset Suprise Attack for Battle Message
          $game_temp.suprise_attack = nil
        end
      # If Enemies Suprised Actors
      elsif $game_temp.suprise_attack == 2
        # Chance of Success for Actors
        success = rand(100) < 50 * enemies_agi / actors_agi
        # If Successful on Suprise Attack
        if success
          # Set Actors to Zero CP
          for actor in $game_party.actors
            actor.cp = 0
          end
          # Set Enemies to Max CP
          for enemy in $game_troop.enemies
            enemy.cp = 65535
          end
        # Not a Successful Suprise attack
        else
          # Reset Suprise Attack for Battle Message
          $game_temp.suprise_attack = nil
        end      
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Add an Actor
  #     actor_id : actor ID
  #--------------------------------------------------------------------------  
  def add_actor(actor_id)
    # Get Actor
    actor = $game_actors[actor_id]
    # If Actor already exists
    if not @battlers.include?(actor)
      # Set New Actor CP to 0
      actor.cp = 0
      # Resets Battle Actions    
      actor.current_action.clear
      # Add to Battlers Array
      @battlers.push(actor)
    end
  end
  #--------------------------------------------------------------------------
  # * Remove Actor
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  def remove_actor(actor_id)
    # Get Actor
    actor = $game_actors[actor_id]
    # Set Actor CP to 0
    actor.cp = 0
    # Resets Battle Actions    
    actor.current_action.clear    
    # Delete Actor from Battlers Array
    @battlers.delete($game_actors[actor_id])
  end    
  #--------------------------------------------------------------------------
  # * Frame Update
  #-------------------------------------------------------------------------- 
  def update
    # If a Battle Event is running
    if $game_system.battle_interpreter.running?
      # Exit accumulating CP for Actors
      return
    end
    # If we have Battlers (both Actors and Enemies)
    if @battlers.size > 0
      # Recalculate Agility Total of all Movable Battlers (not Hidden or Dead)
      @agi_total = total_agility
      # Calculate New CP for each Battler (Actors and Enemies)
	    for battler in @battlers
        # Skip Dead and Unmovable Battlers
        if battler.dead? or not battler.movable?
		      battler.cp = 0
          next
        end        
        # Calculate New CP for Battler
        cp = battler.cp + $game_system.battle_speed * 4096 * battler.agi / @agi_total
        # Clamp CP Values to 0 - 65535
        cp = [[cp, 0].max, 65535].min
        # Assign Value as Battler's New CP
        battler.cp = cp
	    end
    end
  end
  end

cp = battler.cp + $game_system.battle_speed * 4096 * battler.agi / @agi_total

acredito que nessa linha se calcula a velocidade de batalha, vezes o numero 4096, vezes a agilidade  do inimigo que seria estipulada pelo banco de dados, divido pela agilidade total.... o que  me confunde é que o sinal de vezes em teoria deveria funcionar (*)

desde já agradeço
 
Olá [member=2525]KAI GAMES[/member]

Seja muito bem-vindo ao Condado!!

Sobre o script em questão, o problema não é o operador * e sim o $game_system.battle_speed que não está definido e acaba retornando nil, que na linguagem de programação Ruby é uma representação para nulo.

Quando o script tenta fazer nil * 4096, você recebe o erro undefined method `*' for nil:NilClass, pois matematicamente, você não consegue fazer nulo vezes alguma coisa.

Encontrei esse comentário em uma página do próprio autor do script:


Instructions

There are a few options.  Look at each individual Script Page for those options.

The most notable option is Battle Speed.  You can change the Battle Speed in the script itself, or set it by calling $game_system.battle_speed = 1.3

Note:  The Battle Speed setting is quite sensitive.  I've found that a Battle Speed of 1.1 works well for Slow Battles and 1.5 works well for Fast Battles.  A Battle Speed of 1.3 seems to be about the middle of the road.


https://forum.chaos-project.com/index.php?topic=12623.0


Para resolver esse problema adicione o a seguinte linha no começo do método "initialize":


Código:
$game_system.battle_speed = 1.3

Ficando assim:

Código:
def initialize
    # Battle Speed
    $game_system.battle_speed = 1.3

    # Create an empty Array for All Battlers
    @battlers = []
    # Add all Actors to array
    for actor in $game_party.actors
        @battlers.push(actor)
    end    
    # Add all Enemies to array
    for enemy in $game_troop.enemies
        @battlers.push(enemy)
    end
    # Determine Agility Total of all Movable Battlers (not Hidden)
    @agi_total = total_agility
    # If Random CP is Allowed - Demo or Tutorials
    if not $no_random_cp
      # If Suprise Attack
      if $game_temp.suprise_attack
        # Set CP based on who suprised who
        set_suprise_cp
      # No Suprise Attack
      else
        # Set Initial CP with slightly Random Values
        for battler in @battlers
          # Party Size
          size = $game_party.actors.size
          # Randomize Initial CP
          new_cp = 65535*(rand(85)+15)/250 * battler.agi/@agi_total*size
          # Clamp Values to 0 - 65535
          battler.cp = [[new_cp,0].max,65535].min          
        end
      end
    end
  end

Nos avise caso dê certo.
 
Voltar
Topo Inferior