Custom Battle Parameters

Hello! I'm currently working on implementing custom battle parameters. It's similar to that of Yanfly's Skill Cost Manager. I want to make a bp (Battle Points) Bar that works similar to TP, but just takes longer to fill up and allows for stronger attacks. I've got the UI complete now I just need to actually attach some variables to the UI so that it functions the way I want it. 


I have a couple of questions. First I've already been attempting to implement this and I think I'm almost done, however, I've reached a road block due to an error. I've been reading up on documentation and glossing through other similar scripts since yesterday to try to figure this out, but I'm stumped. 


My code: http://pastebin.com/3CSjMwvr


My Error: Line 55, Comparison of fixnum with nil failed.


I'm not sure how bp_cost is returning as nil, it's obviously being set. I've seen other scripts that do this same thing without a problem so I'm completely lost. If there's someone out there who's more experience with Ruby than me I'd like some insight as to what I'm doing wrong.


Also, is there a way I can call and change the bp variable I have to match a custom calculation I've made.

Spoiler
Code:
  def calculate_tp
    actor = {}
    max_actors = item_max - 1
    for i in 0..max_actors
      actor[i] = $game_party.battle_members[i]
    end
    @gauge_variable = (
      actor[0].tp +
      actor[1].tp +
      actor[2].tp +
      actor[3].tp
    )
  end
  
  def update_gauge
    return if @gauge_meter == nil
    sprite_visible(@gauge_meter)
    if @sprite_visible
      calculate_tp
      actor = $game_party.battle_members[0]
      actor.bp = 400
      burst_rate(actor)
      if(@gauge_width <= @burst_mw)
        @gauge_width = @burst_cw
      end
      @gauge_meter_rect = Rect.new(@scroll, 0, @gauge_width, 9)
      @gauge_meter.bitmap.blt(0, 0, @gauge_sprite, @gauge_meter_rect)
      @scroll += 1
      if(@scroll >= @scroll_max)
        @scroll = 20
      end
    end
  end
  
  def sprite_visible(sprite)
    if @sprite_visible
      sprite.opacity += 2 unless @sprite_visible_wait > 0
    else
      sprite.opacity -= 10 ; @sprite_visible_wait = 5
    end
  end
  
  def burst_rate(actor)
    @burst_iw = 0
    @burst_cw = (@burst_iw + (@gauge_variable / item_max)).to_i
    @burst_mw = (actor.hp / 2).to_i
    #actor.bp = @burst_cw
    #actor.bp_cost = 400
  end

As you can see I tried to call it using "actor.bp = @burst_cw" but that didn't yield any results. Could it be because bp is an attr_reader instead of an accessor? 


I usually like to try to figure these things out myself but I'm completely lost here.


Thanks in advance!
I've moved this thread to Learning RGSS3. Please be sure to post your threads in the correct forum next time. Thank you.
uhm this will make it such that the default initialization done on RPG:Skills will not happen which might be pretty bad


  1. alias recall_init initialize

  2.   def initialize

  3.     @bp_cost = 0

  4.     @burst_skill = false

  5.   end



your code should be


alias recall_init initialize
def initialize
recall_init
@bp_cost = 0
@burst_skill = false
end




Also, try changing this line


bp >= skill_bp_cost(skill)


into 


@bp >= skill_bp_cost(skill)

or

self.bp >= skill_bp_cost(skill)


You also overwritten the initialization of Game_BattlerBase, which for the most part is a bad thing to do... Those methods should almost always be aliased to be safe
uhm this will make it such that the default initialization done on RPG:Skills will not happen which might be pretty bad


  1. alias recall_init initialize

  2.   def initialize

  3.     @bp_cost = 0

  4.     @burst_skill = false

  5.   end



your code should be



alias recall_init initialize
def initialize
recall_init
@bp_cost = 0
@burst_skill = false
end




Also, try changing this line



bp >= skill_bp_cost(skill)


into 



@bp >= skill_bp_cost(skill)

or

self.bp >= skill_bp_cost(skill)

Oh yeah, that alias call. You're right, however I had that there before. I must've deleted it on accident when I was messing with the code a bit, sorry about that!


I've tried both @bp and self.bp. Neither seems to work, the problem seems to be with skill.bp_cost.


Thanks for your help though!
from what I can tell, bp_cost should be accessible. Are you trying to run this from a saved game rather than a new one?
Yes exactly! It should be accessible lol. I'm not running it from a saved game at all. I'm actually just running it through the Battle Test in the troops menu. Perhaps I should run it in a New Game?
Try running it in the actual game and see if it works.


also try to change your init code to


alias recall_init initialize
def initialize
recall_init
@bp_cost = 0
@burst_skill = false
p "skill init"
end


and the bp cost calculation to


def skill_bp_cost(skill)
p skill.bp_cost
skill.bp_cost
end




and make sure the console is opened, just so we can see if it's initialized and if the bp_cost is indeed returning nil
Well the problem seems to persist in a New Game as well. I've no idea why I'm getting this error but it's quite frustrating.
have  you tried changing to my above suggestions just to see what's happening via the console? and have you returned the init method to call the aliased one?
Okay, just tried that and yes, it is indeed returning Nil in the console.

Capture.PNG
did you add the p command I put into the init as well (coz I dont see the "skill init" message in your console)? if you added it but its not showing the message then it means that it's not getting initialized
I did add the p command and I was thinking the exact same thing. I've tested some other functions in there that didn't work. But if that's the problem, why would it not be getting initialized?
Hmm if ur running using new game instead of loading a saved one, it should be running the initialize code... can you try to relocate the call to the alias to the last part of that method and see if that changes things?


you can remove the init method that you did, and the attr_accessor call to :bp_cost and burst_skilll and just do this


def bp_cost
@bp_cost = 0 if @bp_cost.nil?
return @bp_cost
end

def burst_skill
@burst_skill = false if @burst_skill.nil?
return @burst_skill
end


And it should work fine after.. this way it's also sure to initialize even if you load a saved game made before the script was added.


but if all skill will have a bp cost of 0 and the burst ones are fixed at 600, you can just check if it's a burst skill or not during the cost calculations..


I hope this does the job, if not, well I can't answer for the next 16 hours. 🙂
That had no effect either. I also tried to just overwrite/recreate the entire initialize code itself, which also didn't work.


Edit: Replacing the accessors worked! Thanks man! I still wonder why it didn't work with the accessor call though.
Maybe you had a code somewhere that edited that same method? 


If not, the only time that it won't initialize is if you are using the load game command (then load a file made before the script was installed) instead of new game. So if you are sure that you tested by using New Game instead of Load Game then it should work fine.


But since it also didn't work in battle test, I would assume you do have another script that overwrites the init method of RPG::Skill, you can try opening the script editor and hit CTRL+SHIFT+F and global search for RPG::Skill and look at all the instances where it appeared.
That's probably it. Thanks for the help, I appreciate it. Hopefully I'll see you around again if I ever encounter another weird error lol.

Original thread: https://forums.rpgmakerweb.com/threads/custom-battle-parameters.72898/