Having trouble writing conditional branches for a script

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
This is the script I'm trying to use:

#==============================================================================
# Get Battle Info [VXA]
# Author: Mesiah A.K.A. Mako Infused
# Version: 1.04
# Contact: www.cetrastudios.com/
#------------------------------------------------------------------------------
# ■ Short Description
#------------------------------------------------------------------------------
# This script allows the developer get more information about the current
# battle without scripting. It allows you to retrieve information and use it
# for eventing purposes.
#
#------------------------------------------------------------------------------
# ͏ Notetags - 0
#------------------------------------------------------------------------------
# There is no notetag options for this script.
#
#------------------------------------------------------------------------------
# ͏ Script Calls - 4
#------------------------------------------------------------------------------
# CALL: battle_info_user
# HELP: This command will get the user of the current action in battle.
#
# CALL: battle_info_used
# HELP: This command will get the current action in battle.
#
# CALL: battle_info_targets
# HELP: This command will get an array of all the current targets of the
#       last skill used in battle.
#       Array starts at 1.
#
# CALL: battle_info_all
# HELP: This command will get an array of all the current battlers.
#       Array starts at 1.
#
# NOTE: To retrieve a single actor/enemy from an array you must append a [id]
#       to the end of the script call. Examples can be found below!
#
#------------------------------------------------------------------------------
# ● Examples:
#------------------------------------------------------------------------------
# CALL: battle_info_user.id
# HELP: This would retrieve the id of the current battler whose executing an
#       action in battle.
#
# CALL: battle_info_user.name
# HELP: This would retrieve the name of the current battler whose executing an
#       action in battle.
#
# CALL: battle_info_used.id
# HELP: This would retrieve the id of the current action that has been executed
#       in battle.
#
# CALL: battle_info_all[1].name
# HELP: This would retrieve the name of the first battler in the battle.
#
# CALL: battle_info_targets[1].name
# HELP: This would retrieve the name of the first target of the last executed
#       action in battle.
#
#------------------------------------------------------------------------------
# ● Customization:
#------------------------------------------------------------------------------
# There is no customization options for this script.
#------------------------------------------------------------------------------
# ● Requirements:
#------------------------------------------------------------------------------
# None
#------------------------------------------------------------------------------
# * Terms:
#------------------------------------------------------------------------------
# - Don't claim you made this script.
# - Credit is appreciated, but not necessary.
#------------------------------------------------------------------------------
# ● Change Log:
#------------------------------------------------------------------------------
# 04/10/2013 - Target retrieval is now possible, error prevention added.
# 04/09/2013 - Rewrote script and made script calls shorter.
# 04/08/2013 - Fixed a type-o, prevented misuse of the script outside of battle.
# 04/05/2013 - Started and finished script.
#==============================================================================

#==============================================================================
# [sTOP] End of Edittable Area
#==============================================================================

$imported = {} if $imported.nil?
$imported["MESI-GetBattleInfo"] = true

#==============================================================================
# ** BattleManager
#==============================================================================

module BattleManager
 
  #--------------------------------------------------------------------------
  # * Alias Create Action Order
  #--------------------------------------------------------------------------
  class <<self; alias mesiah_gbi_make_action_orders  make_action_orders; end
  def self.make_action_orders
    $game_temp.battle_skill_all = mesiah_gbi_make_action_orders.dup
  end
 
end

#==============================================================================
# ** Game_Temp
#==============================================================================

class Game_Temp
 
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :battle_skill_user
  attr_accessor :battle_skill_used
  attr_accessor :battle_skill_all
  attr_accessor :battle_skill_targets
 
  #--------------------------------------------------------------------------
  # * Alias Method: Initialize
  #--------------------------------------------------------------------------
  alias mesiah_gbi_initialize initialize
  def initialize
    mesiah_gbi_initialize
    @battle_skill_user = nil
    @battle_skill_used = nil
    @battle_skill_all = [nil]
    @battle_skill_targets = [nil]
  end
 
end

#==============================================================================
# ** Game_Interpreter
#==============================================================================

class Game_Interpreter
 
  #--------------------------------------------------------------------------
  # * Get Last User
  #--------------------------------------------------------------------------
  def battle_info_user
    return if battle_only_error?
    return $game_temp.battle_skill_user
  end
 
  #--------------------------------------------------------------------------
  # * Last Used Item/Skill
  #--------------------------------------------------------------------------
  def battle_info_used
    return if battle_only_error?
    return $game_temp.battle_skill_used
  end
 
  #--------------------------------------------------------------------------
  # * Get Last Targets
  #--------------------------------------------------------------------------
  def battle_info_targets
    return if battle_only_error?
    return $game_temp.battle_skill_targets
  end
 
  #--------------------------------------------------------------------------
  # * Get All Current Battlers
  #--------------------------------------------------------------------------
  def battle_info_all
    return if battle_only_error?
    return [nil] + $game_temp.battle_skill_all
  end
 
  #--------------------------------------------------------------------------
  # * Checks if the command is valid?
  #--------------------------------------------------------------------------
  def battle_only_error?
    unless SceneManager.scene.class == Scene_Battle
      message = "This script call can only be used in battle!"
      if $imported["MESI-GetErrorInfo"]
        event_script_error(2, message)
      else
        missing = "Install the script 'Get Error Info' for more information"
        msgbox(message + "\n" + missing)
      end
      return true
    end
    return false
  end
 
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
 
  #--------------------------------------------------------------------------
  # * Alias Method: Use Item
  #--------------------------------------------------------------------------
  alias mesiah_gbi_use_item use_item
  def use_item
    $game_temp.battle_skill_user = @subject
    $game_temp.battle_skill_used = @subject.current_action.item
    $game_temp.battle_skill_targets = [nil]
    mesiah_gbi_use_item
  end
 
  #--------------------------------------------------------------------------
  # * Use Skill/Item
  #--------------------------------------------------------------------------
  alias mesiah_gbi_invoke_item invoke_item
  def invoke_item(target, item)
    $game_temp.battle_skill_targets.push(target)
    mesiah_gbi_invoke_item(target, item)
  end
 
end

The problem I'm having is I don't understand how to actually use the information the script calls are retrieving in my events.  For example:

Let's say I write down the script call...

battle_info_user

into my battle event.  Then I wanted to do a conditional branch to see what the ID was of the current user.  How would I write that into a script branch condition so I could actually cause things to happen based on the data the script calls?
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
Please use code- and spoiler tags for putting up a script, this makes your post better readable

There are different script fields in eventing, one of them inside the conditional branches.

To test (for example) if battle_info_user is identical to 2 (as in ID 2 for the actor), you'll have to place that check into that script field.

conditional branch : script : battle_info_user == 2

and then the main branch would be executed if that was the second actor, and the else branch if it was another user.

You can also use some of those commands in the script field of a control vraiable command - that will put the number into that variable for later use.
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
Please use code- and spoiler tags for putting up a script, this makes your post better readable

conditional branch : script : battle_info_user == 2

.
How do I use tags?

I put battle_info_user == 1 into my conditional branch and I'm no longer getting the error.  So I feel like I'm making some progress at least so thanks.  But I still can't get anything to trigger.

I created a common event that looks likes this:

Script: battle_info_user

Conditional Branch: Script: battle_info_user == 1

Text: User = 1

Branch: End

Conditional Branch: Script: battle_info_user == 2

Text: User = 2

Branch: End

Conditional Branch: Script: battle_info_user == 3

Text: User = 3

Branch: End

Conditional Branch: Script: battle_info_user == 4

Text: User = 4

Branch: End

Conditional Branch: Script: battle_info_user == 5

Text: User = 5

Branch: End

Conditional Branch: Script: battle_info_user == 6

Text: User = 6

Branch: End

Conditional Branch: Script: battle_info_user == 7

Text: User = 7

Branch: End

Conditional Branch: Script: battle_info_user == 8

Text: User = 8

Branch: End

I then placed this common event into Effects section of my Heal Skill.  Yet when I use the heal skill none of those Texts show up.  Any ideas?
 
Last edited by a moderator:

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
I've never used spoiler tags so forgive me if I mess up.

Like posted above, you'll want to make a conditional branch with the script call. I took a screen shot of how to do it.

The problem I'm running into is acctualy with the script. You want it to call off the ID, however it's different.. it is actor_id when it's an actor and enemy_id when it's an enemy and doesn't recognize ".id". So calling it doesn't really do much now.

Once you get that part straight then you can do something like your common event you've already made.
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
I've never used spoiler tags so forgive me if I mess up.

Like posted above, you'll want to make a conditional branch with the script call. I took a screen shot of how to do it.

The problem I'm running into is acctualy with the script. You want it to call off the ID, however it's different.. it is actor_id when it's an actor and enemy_id when it's an enemy and doesn't recognize ".id". So calling it doesn't really do much now.

Once you get that part straight then you can do something like your common event you've already made.
Thank you much.  I changed my Conditional Branch: Script: to battle_info_user and I'm actually getting the text to trigger.  I'm not 100% sure what you meant in your second sentence but once I play around with it more I'm hopeful it will become more clear.  Right now I just wanted to figure out how to write the thing in my branch so I could start experimenting with it.  Having that step down will help me a lot.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
Berylstone, if you try to quote this text you'll see four "Tags", that is words in [ ] that are not displayed in my post but change the way it is displayed.

Basically, the tag displayed above this line is the opening spoiler tag.

The tag next line when quoting will be the opening code tag

This is how code is displayed - the number of spaces in front remains and is not removedAnd now the code tag is closed (line above this)
Back to your point:

Please make screenshots of your event - there are too many details that could go wrong with eventing and that would be removed by descriptions like you did.
 
Last edited by a moderator:

Celianna

Tileset artist
Veteran
Joined
Mar 1, 2012
Messages
10,557
Reaction score
5,592
First Language
Dutch
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.


Disregard that, re-opened at OP's request.
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
Berylstone, if you try to quote this text you'll see four "Tags", that is words in [ ] that are not displayed in my post but change the way it is displayed.

Basically, the tag displayed above this line is the opening spoiler tag.

The tag next line when quoting will be the opening code tag

This is how code is displayed - the number of spaces in front remains and is not removedAnd now the code tag is closed (line above this)
Back to your point:

Please make screenshots of your event - there are too many details that could go wrong with eventing and that would be removed by descriptions like you did.
That was my fault about the pre-mature lock.



Just Testing



Here is a screen shot of my event like you asked.

Screen Shot.png

It seems to be working now, but if you see any mistakes feel free to highlight them.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
I don't see any direct mistake in that event, but a few things look unneccessarily complicated.

First, I don't think you need that script command at the beginning - the correct script function will be executed inside the conditional branches.

Second, the naming of the variable indicates that you plan to have several variables holding an actor's level at all times.

That is not neccessary, because you can always load any actor's level into a variable by control variable : game data: actor : actor ID : Level

And you might consider adding another comment to the event: That event only works inside a battle, it cannot be used by skills outside of a battle (because the battle_info-Script would return wrong data or fail completely if called outside a battlescreen.

That might be something you keep in mind now, but game development usually takes months and you don't want to get into problems by forgetting that and suddenly thinking "Oh, let's make a skill with level-based MP-costs for opening the town door"...
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
I don't see any direct mistake in that event, but a few things look unneccessarily complicated.

First, I don't think you need that script command at the beginning - the correct script function will be executed inside the conditional branches.

Second, the naming of the variable indicates that you plan to have several variables holding an actor's level at all times.

That is not neccessary, because you can always load any actor's level into a variable by control variable : game data: actor : actor ID : Level

And you might consider adding another comment to the event: That event only works inside a battle, it cannot be used by skills outside of a battle (because the battle_info-Script would return wrong data or fail completely if called outside a battlescreen.

That might be something you keep in mind now, but game development usually takes months and you don't want to get into problems by forgetting that and suddenly thinking "Oh, let's make a skill with level-based MP-costs for opening the town door"...
Ok that's good to know.  I was confused about that and thought I had to use a script call first to obtain the relevant data before trying to use the conditional branches to trigger events.

[A1:Level] just stands for Actor1's level.  I didn't have any plans to create other variables for that, but thanks for pointing that out just in case.

The fact the script only works in battle may become a problem for me though.  Most of my spells relevant to that event only work in battle.  But the skill I'm working on now - the healing skill for example - I would like to be used outside of battle too.  So seems this script is only a temporary solution and I'm going to have to figure out a way to detect which actor is using a skill outside of battle too. 

There is always something :(
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
But the skill I'm working on now - the healing skill for example - I would like to be used outside of battle too.  So seems this script is only a temporary solution and I'm going to have to figure out a way to detect which actor is using a skill outside of battle too. 
There is always something :(
You can use the damage formula for that as well, but then it might get complicated.

For example, give the user an invisible state "this one has cast heal" by adding a.add_state(##); in front of the healing strength formula, then have the common event check which actor has that state (replace ## with the correct number) in the conditional branches. Don't forget to remove the state after the actor is identified or you'll get problems if more than one actor uses the skill in the same turn.
 

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
642
Reaction score
62
First Language
English
Primarily Uses
You can use the damage formula for that as well, but then it might get complicated.

For example, give the user an invisible state "this one has cast heal" by adding a.add_state(##); in front of the healing strength formula, then have the common event check which actor has that state (replace ## with the correct number) in the conditional branches. Don't forget to remove the state after the actor is identified or you'll get problems if more than one actor uses the skill in the same turn.
I didn't know I could add states through the damage formula.  That's handy to know, so thanks for the input. 
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top