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.

Need help with a simple problem.

Queed

Member

Hi, I just need a simple few lines but I really can't script lol.
I just need the code for:

If an actor is dead, that actor doesnt receive experience. Ty if you help.
 

Queed

Member

Well then it's another problem I have... In my battle script when a battle ends with at least one party member dead, I get this error.
Undefined method '[]' nil for:NilClass...i use the BOF battle system and the lufia style battle result.
 

Anonymous

Guest

I'll need more than that. :-/

What's on the line it's saying is the problem? If you could post that line, plus the whole script(s), that would help a lot. Or post a link to the project file. Either way.
 

Queed

Member

Here's the error line:
Code:
   if @level_flags[i][0] == false

And here's the full script that the error message is in:

Code:
#==============================================================================
# ** Window_BattleResult
#------------------------------------------------------------------------------
#  This window displays amount of gold and EXP acquired at the end of a battle.
#==============================================================================

class Window_BattleResult < Window_Base
  SPEEDS = {"instant" => 32, "faster" => 16, "fast" => 8, 
   "slow" => 4, "slower" => 2, "slowest" => 1}
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     exp       : EXP
  #     gold      : amount of gold
  #     treasures : treasures
  #--------------------------------------------------------------------------
  def initialize(exp, gold, treasures, level_flags)
    @exp = exp
    @gold = gold
    @treasures = treasures
    @level_flags = level_flags
    super(80, 0, 480, 256)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 255
    self.visible = false
    @index = 0
    @wait_count = LufiaII_Result::WAIT_COUNT
    @data = []
    setup_text
    self.contents = Bitmap.new(width - 32, @data.size * 32)
  end
  
  def setup_text
    # Gain exp
    exp_text = LufiaII_Result::GET_EXP_TEXT.dup
    exp_text.gsub!(/\[exp\]/, "#{@exp}")
    exp_text.gsub!(/\[words\]/, LufiaII_Result::WORDS_EXP)
    @data.push(exp_text)
    # Gain gold
    gold_text = LufiaII_Result::GET_GOLD_TEXT.dup
    gold_text.gsub!(/\[gold\]/, "#{@gold}")
    gold_text.gsub!(/\[words\]/, $data_system.words.gold)
    @data.push(gold_text)
    # Gain Treasures
    for i in 0...@treasures.size
      item_text = LufiaII_Result::GET_ITEM_TEXT.dup
      item_text.gsub!(/\[icon\]/, "\001[#{i}]")
      item_text.gsub!(/\[name\]/, "#{@treasures[i].name}")
      @data.push(item_text)
    end
    # Blank Line
    @data.push("")
    # Actor Stuff
   for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      level_text = LufiaII_Result::NEXT_LEVEL_TEXT.dup
      level_text.gsub!(/\[name\]/, "#{actor.name}")
      level_text.gsub!(/\[amount\]/, "#{actor.next_exp - actor.now_exp}")
      if @level_flags[i][0] == false
        @data.push(level_text)
      else
        levelup_text = LufiaII_Result::LEVEL_UP_TEXT.dup
        levelup_text.gsub!(/\[name\]/, actor.name)
        levelup_text.gsub!(/\[level\]/, "#{actor.level}")
        @data.push(levelup_text)
        skills = $data_classes[actor.class_id].learn_skills(actor.level)
        actor.hp = actor.maxhp 
        actor.sp = actor.maxsp
        for j in 0...skills.size
          skill_learn_text = LufiaII_Result::GET_SKILL_TEXT.dup
          skill_learn_text.gsub!(/\[icon\]/, "\003|#{skills[j]}|")
          skill_learn_text.gsub!(/\[name\]/, $data_skills[skills[j]].name)
          @data.push(skill_learn_text)
        end
        for j in 0...LufiaII_Result::STATS.size
          stat_text = LufiaII_Result::STAT_UP_TEXT.dup
          stat_text.gsub!(/\[stat\]/, LufiaII_Result::STAT_NAMES[j])
          amount = actor.stat_change(j, @level_flags[actor.index][1])
          stat_text.gsub!(/\[amount\]/, "#{amount}")
          @data.push(stat_text)
        end
        @data.push(level_text)
        @data.push("") if i != $game_party.actors.size - 1
      end
    end
    @data.push("")
    cgold_text = LufiaII_Result::GOLD_TEXT.dup
    cgold_text.gsub!(/\[gold\]/, "#{$game_party.gold}")
    cgold_text.gsub!(/\[words\]/, $data_system.words.gold)    
    @data.push(cgold_text)
  end
  
      
  def update
    if @scrolling
      @scroll_time -= 1
      self.oy += SPEEDS[LufiaII_Result::SCROLL_SPEED.downcase]
      @scrolling = false if @scroll_time == 0
      return
    end
    if LufiaII_Result::WAIT_COUNT != nil
      @wait_count -= 1
      if @wait_count == 0
        @wait_count = LufiaII_Result::WAIT_COUNT
        if @data.size - 1 >= @index
          refresh 
          @index += 1
          @scrolling = true if @index > 7
          @scroll_time = 32 / SPEEDS[LufiaII_Result::SCROLL_SPEED.downcase] if @scrolling
        else
          dispose
        end
        return
      end
    end
    if LufiaII_Result::PUSH_BUTTON and Input.trigger?(Input::C)
      @wait_count = LufiaII_Result::WAIT_COUNT
      if @data.size - 1 >= @index
        refresh 
        @index += 1
        @scrolling = true if @index > 7
        @scroll_time = 32 / SPEEDS[LufiaII_Result::SCROLL_SPEED.downcase] if @scrolling
      else
        dispose
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    x = 0
    text = @data[@index]
    text.gsub!(/\[right\]/, "\002")
    text = text.split("\002")
    return if text == []
    for string in text[0].split(/\001|\003|\s/)
      if string.sub!(/\[([0-9]+)\]/, "") != nil
        index = $1.to_i
        bitmap = RPG::Cache.icon(@treasures[index].icon_name)
        rect = bitmap.rect
        self.contents.blt(x, @index * 32, bitmap, rect)
        x += bitmap.width
      elsif string.sub!(/\|([0-9]+)\|/, "") != nil
        skill_id = $1.to_i
        bitmap = RPG::Cache.icon($data_skills[skill_id].icon_name)
        rect = bitmap.rect
        self.contents.blt(x, @index * 32, bitmap, rect)
        x += bitmap.width        
      else
        self.contents.draw_text_outline(x, @index * 32, width - 32, 32, string)
        x += contents.text_size(string).width
      end
      x += contents.text_size(" ").width
    end
    if text[1] != nil
      self.contents.draw_text_outline(0, @index * 32, width - 32, 32, text[1], 2)
    end
  end
end
 

Anonymous

Guest

Sorry, that's still not enough to track down the problem. I really need either all the scripts (so I can install it myself), your scripts.rxdata file, or a project file.

Right now, all I can tell you is either @level_flags is nil, or @level_flags is nil for some value of i.
 
In addition to what ccoa said in her post add this line before the line with the error

Code:
p @level_flags, i

and test run your game and tell me what pops up in the Windows Dialog Box

also the formatting appears a bit off (something I rarely do...) did you edit the script, if so what did you edit?
 
I also had the same problem as Queed, that the battle result hung and died when a character was dead at the end of a battle; so I went looking at the script...
Though the script hangs on the Window_Battleresult script; it seems to do so because it cannot find a value for @level_flags
So I went and found where this is defined... Its in the Scene_Battle under the comment #Obtaining EXP
Code:
# Obtaining EXP
    level_flags = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        #EDITS
        if last_level != actor.level
          level_flags[i] = [true, last_level] 
        else
          level_flags[i] = [false]
        end
      end
    end
Yup, this is the criminal. Its all well and good when the actor.cant_get_exp? == false, like it would be under most circumstances. But theres no contingency. What if its true? Then it can't return a value for level_flags, right?

I fixed it with this
Code:
    # Obtaining EXP
    level_flags = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        #EDITS
        if last_level != actor.level
          level_flags[i] = [true, last_level] 
        else
          level_flags[i] = [false]
        end
        #EDITS
        [B]elsif actor.cant_get_exp? == true
        last_level = actor.level
        level_flags[i] = [false][/B]
      end
    end
Now, I'm no coder, so that is probably crap coding; but it works now. I tested it with an item that KO's a character, then finished a battle against a wussy monster, and it now seems OK.

Hope that helps you too. (Yes, I already posted this in Lufia Style Report topic as well, since FreakishFae had the same problem, but since my search of the forum turned this up too, I figured I should post again here to help.)

EDIT: Fyad Oh Noes, I hope this isn't Necroposting. Big Apologies if it is...
 

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