
-----------------------------------
StarGateSG-1
Sun Mar 13, 2005 8:39 am

Help with Ruby (Final Word)
-----------------------------------
I am trying out on of those RPG malers for fun.
And i am having a problem with the script, (mainly becasue comments are in chinese, lol) but i need to rewrite some parts. and i am not sure how?

def for_one_friend_hp0?
    # &#31278;&#21029;&#12364;&#12473;&#12461;&#12523;&#12391;&#12289;&#21177;&#26524;&#31684;&#22258;&#12364;&#21619;&#26041;&#21336;&#20307; (HP 0 &#12398;&#12415;) &#12398;&#22580;&#21512;
    if @kind == 1 and [5].include?($data_skills[@skill_id].scope)
      return true
    end
    # &#31278;&#21029;&#12364;&#12450;&#12452;&#12486;&#12512;&#12391;&#12289;&#21177;&#26524;&#31684;&#22258;&#12364;&#21619;&#26041;&#21336;&#20307; (HP 0 &#12398;&#12415;) &#12398;&#22580;&#21512;
    if @kind == 2 and [5].include?($data_items[@item_id].scope)
      return true
    end
    return false
  end

This is the problem piece if you wnat to know more go download it at
http://archives.rpginfinity.com/makers/rpg_maker_xp
AN overview of the problem is when you choose to attack it will come up with an error about 'Game_BattleAction' 62 (line i think)
No Method Error
'scope' nil:NilClass
It be really great if you could help me
O ya does anyone know of a site that can chnage chinese to english???

-----------------------------------
Martin
Sun Mar 13, 2005 11:42 am


-----------------------------------
Try http://www.altavista.com/tr

-----------------------------------
wtd
Sun Mar 13, 2005 11:47 am


-----------------------------------
It's actually Japanese.  You can tell because of the use of Hiragana as well as Kanji characters.

As for your problem...

[5].include?($data_skills[@skill_id].scope)

Causes problems because 

$data_skills[@skill_id]

Is nil, and nil is an object of the NilClass class, which doesn't have a method 'scope'.

if @kind == 2 and $data[@skill_id] and [5].include?($data_skills[@skill_id].scope)

But it can be more simply written as:

if @kind == 2 and $data[@skill_id] and $data_skills[@skill_id].scope == 5

-----------------------------------
wtd
Sun Mar 13, 2005 2:20 pm


-----------------------------------
Further explanation:  

$data_skills

Is an Array or Hash.  You get nil from:

$data_skills[@skill_id]

Because 

@skill_id

Isn't a valid index of the array or hash.

-----------------------------------
StarGateSG-1
Sun Mar 13, 2005 6:15 pm


-----------------------------------
Well thanks for the help, it didn;t work though maybe you could take a deeper lok at all the code. I will post all of the Game_BattleAction. I will also tranlate this time.'


#==============================================================================
# &#9632; Game_BattleAction
#------------------------------------------------------------------------------
# &#12288;Action (the conduct which is in the midst of fighting) it is the class #which is handled. This class is used inside Game_Battler Class
#==============================================================================

class Game_BattleAction
  #--------------------------------------------------------------------------
  # &#9679; Open instance variable
  #--------------------------------------------------------------------------
  attr_accessor :speed                    # Speed
  attr_accessor :kind                     # Classification (basis/skill/item)
  attr_accessor :basic                    # The basis (attack/defense/it 
                                                   # escapes))
  attr_accessor :skill_id                 # Skill ID
  attr_accessor :item_id                  # Item ID 
 attr_accessor :target_index             # Object index
  attr_accessor :forcing                  # Forced flag
  #--------------------------------------------------------------------------
  # &#9679; Object initialization
  #--------------------------------------------------------------------------
  def initialize
    clear
  end
  #--------------------------------------------------------------------------
  # &#9679; Clearing
  #--------------------------------------------------------------------------
  def clear
    @speed = 0
    @kind = 0
    @basic = 3
    @skill_id = 0
    @item_id = 0
    @target_index = -1
    @forcing = false
  end
  #--------------------------------------------------------------------------
  # &#9679; Validity decision
  #--------------------------------------------------------------------------
  def valid?
    return (not (@kind == 0 and @basic == 3))
  end
  #--------------------------------------------------------------------------
  # &#9679; Decision for friend single unit
  #--------------------------------------------------------------------------
  def for_one_friend?
    # When classification with skill, the effective range the friend single      #unit (HP 0 is included),
    if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope)
      return true
    end
    # When classification with the item, the effective range the friend       #single unit (HP 0 is included)
    if @kind == 2 and [3, 5].include?($data_items[@item_id].scope)
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  # &#9679; For friend single unit (HP 0) decision
  #--------------------------------------------------------------------------
  def for_one_friend_hp0?
    # When classification with skill, the effective range the friend single #unit (only HP 0) is,
    if @kind == 1 and [5].include?($data_skills[@skill_id].scope)
      return true
    end
    # When classification with the item, the effective range the friend #single unit (only HP 0) is,
    if @kind == 2 and $data[@skill_id] and $data_skills[@skill_id].scope == 5
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  # &#9679; Random target (for actor)
  #--------------------------------------------------------------------------
  def decide_random_target_for_actor
    # It diverges in the effective range
   # if for_one_friend_hp0?
      battler = $game_party.random_target_actor_hp0
    elsif for_one_friend?
      battler = $game_party.random_target_actor
    else
      battler = $game_troop.random_target_enemy
    end
    # If the object exists, you acquire the index, when the 
# object does not exist, clearing action
    if battler != nil
      @target_index = battler.index
    else
      clear
    end
  end
  #--------------------------------------------------------------------------
  # &#9679; Random target (for enemy)
  #--------------------------------------------------------------------------
  def decide_random_target_for_enemy
    # It diverges in the effective range
    if for_one_friend_hp0?
      battler = $game_troop.random_target_enemy_hp0
    elsif for_one_friend?
      battler = $game_troop.random_target_enemy
    else
      battler = $game_party.random_target_actor
    end
    # If the object exists, you acquire the index, when the 
# object does not exist, clearing action
    if battler != nil
      @target_index = battler.index
    else
      clear
    end
  end
  #--------------------------------------------------------------------------
  # &#9679; Rust target (for actor)  #--------------------------------------------------------------------------
  def decide_last_target_for_actor
    # If effective range friend single unit if actor, other than that enemy
    if @target_index == -1
      battler = nil
    elsif for_one_friend?
      battler = $game_party.actors[@target_index]
    else
      battler = $game_troop.enemies[@target_index]
    end
    # When the object does not exist, clearing action
    if battler == nil or not battler.exist?
      clear
    end
  end
  #--------------------------------------------------------------------------
  # &#9679; Rust target (for enemy)
  #--------------------------------------------------------------------------
  def decide_last_target_for_enemy
    # If effective range friend single unit if enemy, other than that actor
    if @target_index == -1
      battler = nil
    elsif for_one_friend?
      battler = $game_troop.enemies[@target_index]
    else
      battler = $game_party.actors[@target_index]
    end
    # When the object does not exist, clearing action
    if battler == nil or not battler.exist?
      clear
    end
  end
end

Here it is!
ouch that took like 15 - 20 mins to translate i hate to have to translate the whole program good thing there is a good debuger.
The error agins is
??????'Game_BattleAction'?62???No Method Error???????
undefined method 'scope' for nil:NilClass

-----------------------------------
StarGateSG-1
Sun Mar 13, 2005 6:16 pm


-----------------------------------
O ya one last thing if you find the error isn't here download it at the above site, this is a major problem and needs to be dealt with the company, so if we can report it thats good.

-----------------------------------
wtd
Mon Mar 14, 2005 1:11 am


-----------------------------------
There's one problem.  The $ in 

$data_skills

Indicates that this is a global variable.  I'd have to see how this is setup to really be able to help.

While I appreciate the use of Ruby, this unfortunately doesn't look like very good code.

-----------------------------------
StarGateSG-1
Mon Mar 14, 2005 11:15 am


-----------------------------------
Like i said go download the program at the site in my first post here.
I didn't right this code nor do i really know ruby, and there are well over 50 sections and i can't put them all on here.
O ya soemtimes it works know soemimes not.

-----------------------------------
StarGateSG-1
Mon Mar 14, 2005 11:18 am


-----------------------------------

 def for_one_friend?
    # &#31278;&#21029;&#12364;&#12473;&#12461;&#12523;&#12391;&#12289;&#21177;&#26524;&#31684;&#22258;&#12364;&#21619;&#26041;&#21336;&#20307; (HP 0 &#12434;&#21547;&#12416;) &#12398;&#22580;&#21512;
    if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope)
      return true
    end
    # &#31278;&#21029;&#12364;&#12450;&#12452;&#12486;&#12512;&#12391;&#12289;&#21177;&#26524;&#31684;&#22258;&#12364;&#21619;&#26041;&#21336;&#20307; (HP 0 &#12434;&#21547;&#12416;) &#12398;&#22580;&#21512;
    if @kind == 2 and [3, 5].include?($data_items[@item_id].scope)
      return true
    end
    return false
  end

This is the second piece that has problems, if someone could fix this it would be good I am pretty sure.

-----------------------------------
wtd
Thu Mar 17, 2005 2:10 am


-----------------------------------
As you've noted, the problem is with this line:

if @kind == 1 and [5].include?($data_skills[@skill_id].scope)

And more specifically this:

[5].include?($data_skills[@skill_id].scope)

Even more specifically:

$data_skills[@skill_id].scope

When you get a NoMethodError it means you're trying to call a method that the object doesn't have.  

$data_skills

Is an array.  It's also a global variable, meaning it's visible to everything in the program (the $ gives this away).

@skill_id 

Is the index for that array.

Now, what happens when skill_id is too large, and doesn't represent a skill in the $data_skills array?  Well, I get "nil".  The "nil" value is Ruby's equivalent to nothing, and it has very few methods.

if @kind == 1 and skill = $data_skills[@skill_id] and [5].include? skill.scope

Since Ruby's conditionals (if/elsif/else) short-circuit, I know that if any of these conditions is false, the rest won't even be evaluated.  If:

$data_skills[@skill_id]

Is nil, then Ruby will never try to call the scope method, and the error won't occur.

-----------------------------------
wtd
Thu Mar 17, 2005 11:46 am


-----------------------------------
if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope)

Poses the same problem, so the solution is the same.

if @kind == 1 and and skill = $data_skills[@skill_id] and [3, 5].include? skill.scope

-----------------------------------
StarGateSG-1
Thu Mar 17, 2005 4:56 pm


-----------------------------------
Thank you very much, I hope this is the last problem I find.

-----------------------------------
StarGateSG-1
Thu Mar 17, 2005 5:11 pm


-----------------------------------
Well I found more problems, maybe you should take alot look at the whole program (RPG Maker XP)

cuase there oculd be alot more erros I am not finding yet, but it take forever to debug when i don't know ruby

But here is the next problem.


 #--------------------------------------------------------------------------
  # &#9679; Skill action result compilation
  #--------------------------------------------------------------------------
  def make_skill_action_result
    # Acquiring skill
    @skill = $data_skills[@active_battler.current_action.skill_id]
    # If it is not forced action
    unless @active_battler.current_action.forcing
      # When with SP and so on is cut off and it becomes not be able to use.
      unless @active_battler.skill_can_use?(@skill.id)
        # Clearing the buffer of the action forced object
        $game_temp.forcing_battler = nil
        # It moves to step 1
        @phase4_step = 1
        return
      end
    end
    # SP consumption
   @active_battler.sp -= @skill.sp_cost
    # Refreshing the status window
    @status_window.refresh
    # Indicating skill name in the help window
    @help_window.set_text(@skill.name, 1)
    # Setting animation ID
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    # Setting common event ID
    @common_event_id = @skill.common_event_id
    # Setting the object side butler
    set_target_battlers(@skill.scope)
    # Applying the effect of skill
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
  
* this is the error line
This time I know what happens though, you use the skill , but you don't have enough mana, so it needs like an if statement, to check if you have enough mana, if not then can't use skill

-----------------------------------
StarGateSG-1
Fri Mar 18, 2005 11:05 am


-----------------------------------

def decide_random_target_for_actor 
    # It diverges in the effective range 
   # if for_one_friend_hp0? 
      battler = $game_party.random_target_actor_hp0 
    **elsif for_one_friend? 
      battler = $game_party.random_target_actor 
    else 
      battler = $game_troop.random_target_enemy 
    end 
    # If the object exists, you acquire the index, when the 
# object does not exist, clearing action 
    if battler != nil 
      @target_index = battler.index 
    else 
      clear 
    end 
  end 

** another problem, no clue about this one, but this hgappend when there is more than one monster being fought at the same time.

-----------------------------------
StarGateSG-1
Mon Mar 21, 2005 4:46 pm


-----------------------------------
This is ruby right?

anyways I don't think the problem is with having egough mana. 

More coming

...
minutes later

I was right and wrong the basic attack is calling apon mana even though it costs nothing!

... 
mintues later

The problem is it is treating the attack as a skill if you refer to the GameAction_Battler


#============================================================================== 
# &#9632; Game_BattleAction 
#------------------------------------------------------------------------------ 
# &#12288;Action (the conduct which is in the midst of fighting) it is the class #which is handled. This class is used inside Game_Battler Class 
#============================================================================== 

class Game_BattleAction 
  #-------------------------------------------------------------------------- 
  # &#9679; Open instance variable 
  #-------------------------------------------------------------------------- 
  attr_accessor :speed                    # Speed 
  attr_accessor :kind                     # Classification (basis/skill/item) 
  attr_accessor :basic                    # The basis (attack/defense/it 
                                                   # escapes)) 
  attr_accessor :skill_id                 # Skill ID 
  attr_accessor :item_id                  # Item ID 
 attr_accessor :target_index             # Object index 
  attr_accessor :forcing                  # Forced flag 
  #-------------------------------------------------------------------------- 
  # &#9679; Object initialization 
  #-------------------------------------------------------------------------- 
  def initialize 
    clear 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Clearing 
  #-------------------------------------------------------------------------- 
  def clear 
    @speed = 0 
    @kind = 0 
    @basic = 3 
    @skill_id = 0 
    @item_id = 0 
    @target_index = -1 
    @forcing = false 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Validity decision 
  #-------------------------------------------------------------------------- 
  def valid? 
    return (not (@kind == 0 and @basic == 3)) 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Decision for friend single unit 
  #-------------------------------------------------------------------------- 
  def for_one_friend? 
    # When classification with skill, the effective range the friend single      
    #unit (HP 0 is included), 
   if @kind == 1 and skill = $data_skills[@skill_id] and [3, 5].include? skill.scope 
return true 
    end 
    # When classification with the item, the effective range the friend       
    #single unit (HP 0 is included) 
   if @kind == 2  and skill = $data_skills[@skill_id] and [3, 5].include? skill.scope 
return true 
    end 
    return false 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; For friend single unit (HP 0) decision 
  #-------------------------------------------------------------------------- 

** Here I think
  def for_one_friend_hp0? 
    # When classification with skill, the effective range the friend single 
    #unit (only HP 0) is, 
   if @kind == 1 and skill = $data_skills[@skill_id] and [5].include? **skill.scope 
return true 
    end 
    # When classification with the item, the effective range the friend 
    #single unit (only HP 0) is, 
 if @kind == 2 and skill = $data_skills[@skill_id] and [5].include? **skill.scope 
return true 
    end 
    return false 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Random target (for actor) 
  #-------------------------------------------------------------------------- 
  def decide_random_target_for_actor 
    # It diverges in the effective range 
   # if for_one_friend_hp0? 
    if for_one_friend_hp0?
      battler = $game_party.random_target_actor_hp0
    elsif for_one_friend?
      battler = $game_party.random_target_actor
    else
      battler = $game_troop.random_target_enemy
    end
    # If the object exists, you acquire the index, when the 
# object does not exist, clearing action 
    if battler != nil 
      @target_index = battler.index 
    else 
      clear 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Random target (for enemy) 
  #-------------------------------------------------------------------------- 
  def decide_random_target_for_enemy 
    # It diverges in the effective range 
    if for_one_friend_hp0? 
      battler = $game_troop.random_target_enemy_hp0 
    elsif for_one_friend? 
      battler = $game_troop.random_target_enemy 
    else 
      battler = $game_party.random_target_actor 
    end 
    # If the object exists, you acquire the index, when the 
# object does not exist, clearing action 
    if battler != nil 
      @target_index = battler.index 
    else 
      clear 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Rust target (for actor)  #-------------------------------------------------------------------------- 
  def decide_last_target_for_actor 
    # If effective range friend single unit if actor, other than that enemy 
    if @target_index == -1 
      battler = nil 
    elsif for_one_friend? 
      battler = $game_party.actors[@target_index] 
    else 
      battler = $game_troop.enemies[@target_index] 
    end 
    # When the object does not exist, clearing action 
    if battler == nil or not battler.exist? 
      clear 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # &#9679; Rust target (for enemy) 
  #-------------------------------------------------------------------------- 
  def decide_last_target_for_enemy 
    # If effective range friend single unit if enemy, other than that actor 
    if @target_index == -1 
      battler = nil 
    elsif for_one_friend? 
      battler = $game_troop.enemies[@target_index] 
    else 
      battler = $game_party.actors[@target_index] 
    end 
    # When the object does not exist, clearing action 
    if battler == nil or not battler.exist? 
      clear 
    end 
  end 
end 


There is a problem with the way it uses basic attacks.

-----------------------------------
StarGateSG-1
Wed Mar 30, 2005 8:28 am


-----------------------------------
The Ruby I was using was RGSS so therefore no one here uses it, unless you happen to use rmxp. So I am ending this.
