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.

Game_battler copy object problem

Im trying to make a weapon that calls a skill after dealing damage. For now, i was dealing with the action_battlers array, trying to add a new magic action before the attack action.

anyway, the main problem is this_:
actor2 = actor.clone
actor2.current_action.kind = 1
actor2.current_action.skill_id = value[1]
actor2.improved_effect = 1
actor.current_action.kind = 0
p actor2.current_action.kind
p actor.current_action.kind

The p' says 0 and 0. Why? I cant modify one without modifing the other, and i have already used the clone/dup, what im doing wrong?
Code:
    

    # Add actor to @action_battlers array

    for actor in $game_party.actors

      # Checks for adding a skill in a weapon attack

      if $data_weapons[actor.weapon_id].call_skill

        p 'ok'

        value = $data_weapons[actor.weapon_id].call_skill

        actor2 = actor.clone

        # Changue the action kind and skill id

        actor2.current_action.kind = 1

        actor2.current_action.skill_id = value[1]

        actor2.improved_effect = 1

        actor.current_action.kind = 0

        p actor2.current_action.kind

        p actor.current_action.kind

        @action_battlers.push(actor)

        @action_battlers.push(actor2)

      else

        @action_battlers.push(actor)

      end

    end
 
current_action is not cloned by cloning the Game_Battler object, so both actor and actor2 will have the same current_action object. For completely cloning the actor object, you can do something like:
Code:
actor2 = Marshal.load(Marshal.dump(actor))
 

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