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.

help with script for a conditional branch

What I'm trying to do is, have a conditional branch that checks whether or not a certain character (in this exact case it would be Actor 001) chose to perform a regular attack. If said character attacked, I would then check the weapon with another CB. If both conditions were met, I then add to a variable which would be that characters proficiency with whatever weapon. All I need though, is the script to determine if he attacked or not.
Thanks
 
This should work with the default bs. It appends the check to method update_phase4_step2  (Frame Update (main phase step 2 : start action))
Code:
class Scene_Battle
  alias check_attack_update_phase4_step2 update_phase4_step2
  def update_phase4_step2
    # Original call
    check_attack_update_phase4_step2
    # check if the active battler is actor 001
    if @active_battler != nil and @active_battler.is_a?(Game_Actor) and @active_battler.id == 1
      # check if the current action is attack
      if @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 0
        # do something
      end
    end
  end
end

Replace "# do something" with the code you want executed.
 
Actually, to make sure I don't screw anything up, do I just add this to the end of the Start Action right before the battle action result? I also forgot something. Since the #do something will be replaced by adding to a variable, I wanted to know if I could summon that variable in the EVENT conditional branch. The 3rd page has a line for script and I figured that's all that's needed to check a variable that's set in script. Thanks again.
 
You can put the code in a new page of the script editor, just before Main. Since it uses aliasing it automatically adds itself up to the right place.

Yes you can use a script condition like this one:
$game_variables[20]>5
 
So $game_variables is how I would access the variables I normally set with events? In that case, I shouldn't have any more trouble with this (knock on wood). Thank you very much for the help.
 
It's what you gave me, but I changed the actor ID from 1 to 6 and tried to call a common event instead of adding to a variable.

class Scene_Battle
  alias check_attack_update_phase4_step2 update_phase4_step2
  def update_phase4_step2
    # Original call
    check_attack_update_phase4_step2
    # check if the active battler is actor 006
    if @active_battler != nil and @active_battler.is_a?(Game_Actor) and @active_battler.id == 6
      # check if the current action is attack
      if @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 0
        then common_event = $data_common_events[@parameters[06]] # do something
      end
    end
  end
end

Edit: Would it be possible to use a line or two of script in an event conditional branch? That would be the easiest for me to work with.
 
Calling a common event is a bit more complicated, that line you wrote does not call the common event.

If you can move around the problem by using some line of script in the conditional branch, here is how it works. In the fourth tab of the conditional branch command click on the event radio button and you can write your text. Your text becomes the condition that needs to be verified in order to execute the body of the "then" branch of the command, e.g. it can be "$game_temp.a_variable == 6" or "($game_swithches[5] == true) and ($game_swithches[2] == false)"...
 
Right. I tried that too after changing the script to try a different actor id. I guess I either didn't use the right lines or those lines couldn't be used that way because I got a syntax error when I tried to attack. What lines could I use in the event conditional branch to check which actor is attacking?
 
Ok, let's go back to the first solution and call a common event.
Add this before Main.

Code:
class Interpreter
  attr_accessor :depth
  attr_accessor :child_interpreter
end

And then where in the code i wrote you before there's "do something" call the common event number n

Code:
$game_system.map_interpreter.child_interpreter = Interpreter.new($game_system.map_interpreter.depth + 1)
$game_system.map_interpreter.child_interpreter.setup($data_common_events[n].list,n)

This should work.
 
Ok, as long as I remove the code you first gave me (the one that checked if actor 1 was attacking) there is no error. If I have them both in at the same time there is a system stack error. However, it works on it's own but the common events I tried with it didn't seem to do anything. Too double check, I tried a common event I had set up that ends with a text message, and the message never appeared. I am using Syvkal's Agility Based Battle code, and since then, calling common events from the troop menu hasn't worked well if I tried to call it on a turn number. I don't know if that would effect it or not.
 

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