Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with Ruby (Final Word)
Index -> Programming, Ruby -> Ruby Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
StarGateSG-1




PostPosted: Sun Mar 13, 2005 8:39 am   Post subject: 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?
code:

def for_one_friend_hp0?
    # 種別がスキルで、効果範囲が味方単体 (HP 0 のみ) の場合
    if @kind == 1 and [5].include?($data_skills[@skill_id].scope)
      return true
    end
    # 種別がアイテムで、効果範囲が味方単体 (HP 0 のみ) の場合
    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???
Sponsor
Sponsor
Sponsor
sponsor
Martin




PostPosted: Sun Mar 13, 2005 11:42 am   Post subject: (No subject)

Try http://www.altavista.com/tr
wtd




PostPosted: Sun Mar 13, 2005 11:47 am   Post subject: (No subject)

It's actually Japanese. You can tell because of the use of Hiragana as well as Kanji characters.

As for your problem...

code:
[5].include?($data_skills[@skill_id].scope)


Causes problems because

code:
$data_skills[@skill_id]


Is nil, and nil is an object of the NilClass class, which doesn't have a method 'scope'.

code:
if @kind == 2 and $data[@skill_id] and [5].include?($data_skills[@skill_id].scope)


But it can be more simply written as:

code:
if @kind == 2 and $data[@skill_id] and $data_skills[@skill_id].scope == 5
wtd




PostPosted: Sun Mar 13, 2005 2:20 pm   Post subject: (No subject)

Further explanation:

code:
$data_skills


Is an Array or Hash. You get nil from:

code:
$data_skills[@skill_id]


Because

code:
@skill_id


Isn't a valid index of the array or hash.
StarGateSG-1




PostPosted: Sun Mar 13, 2005 6:15 pm   Post subject: (No subject)

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.'

code:

#==============================================================================
# ■ Game_BattleAction
#------------------------------------------------------------------------------
#  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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● Object initialization
  #--------------------------------------------------------------------------
  def initialize
    clear
  end
  #--------------------------------------------------------------------------
  # ● Clearing
  #--------------------------------------------------------------------------
  def clear
    @speed = 0
    @kind = 0
    @basic = 3
    @skill_id = 0
    @item_id = 0
    @target_index = -1
    @forcing = false
  end
  #--------------------------------------------------------------------------
  # ● Validity decision
  #--------------------------------------------------------------------------
  def valid?
    return (not (@kind == 0 and @basic == 3))
  end
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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




PostPosted: Sun Mar 13, 2005 6:16 pm   Post subject: (No subject)

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




PostPosted: Mon Mar 14, 2005 1:11 am   Post subject: (No subject)

There's one problem. The $ in

code:
$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




PostPosted: Mon Mar 14, 2005 11:15 am   Post subject: (No subject)

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.
Sponsor
Sponsor
Sponsor
sponsor
StarGateSG-1




PostPosted: Mon Mar 14, 2005 11:18 am   Post subject: (No subject)

code:

 def for_one_friend?
    # 種別がスキルで、効果範囲が味方単体 (HP 0 を含む) の場合
    if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope)
      return true
    end
    # 種別がアイテムで、効果範囲が味方単体 (HP 0 を含む) の場合
    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




PostPosted: Thu Mar 17, 2005 2:10 am   Post subject: (No subject)

As you've noted, the problem is with this line:

code:
if @kind == 1 and [5].include?($data_skills[@skill_id].scope)


And more specifically this:

code:
[5].include?($data_skills[@skill_id].scope)


Even more specifically:

code:
$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.

code:
$data_skills


Is an array. It's also a global variable, meaning it's visible to everything in the program (the $ gives this away).

code:
@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.

http://rubycentral.com/ref/ref_c_nilclass.html

Now, I can check for this. If $data_skills[@skill_id] is nil, it will evaluate to false in a conditional. Otherwise it will evaluate to true. I'll assign it to a temporary variable to save myself some typing.

code:
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:

code:
$data_skills[@skill_id]


Is nil, then Ruby will never try to call the scope method, and the error won't occur.
wtd




PostPosted: Thu Mar 17, 2005 11:46 am   Post subject: (No subject)

code:
if @kind == 1 and [3, 5].include?($data_skills[@skill_id].scope)


Poses the same problem, so the solution is the same.

code:
if @kind == 1 and and skill = $data_skills[@skill_id] and [3, 5].include? skill.scope
StarGateSG-1




PostPosted: Thu Mar 17, 2005 4:56 pm   Post subject: (No subject)

Thank you very much, I hope this is the last problem I find.
StarGateSG-1




PostPosted: Thu Mar 17, 2005 5:11 pm   Post subject: (No subject)

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.

code:

 #--------------------------------------------------------------------------
  # ● 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




PostPosted: Fri Mar 18, 2005 11:05 am   Post subject: (No subject)

code:

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




PostPosted: Mon Mar 21, 2005 4:46 pm   Post subject: (No subject)

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

code:

#==============================================================================
# ■ Game_BattleAction
#------------------------------------------------------------------------------
#  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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● Object initialization
  #--------------------------------------------------------------------------
  def initialize
    clear
  end
  #--------------------------------------------------------------------------
  # ● Clearing
  #--------------------------------------------------------------------------
  def clear
    @speed = 0
    @kind = 0
    @basic = 3
    @skill_id = 0
    @item_id = 0
    @target_index = -1
    @forcing = false
  end
  #--------------------------------------------------------------------------
  # ● Validity decision
  #--------------------------------------------------------------------------
  def valid?
    return (not (@kind == 0 and @basic == 3))
  end
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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
  #--------------------------------------------------------------------------
  # ● 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.
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: