Jump to content
Sign in to follow this  
Tsukihime

Using Conditional Branch Event Commands for Script Input

Recommended Posts

This tutorial describes how conditional branch commands are used as script input. This command is a very convenient way to ask users to specify input, especially if you're working with conditions. This may be easier to use

 

conditionalbranchinput0.jpg

 

Instead of this

conditionalbranchinput2-e1387589294224.j

 

This tutorial shows how to use these commands in your scripts, and how you can achieve complex logic using only these commands.

 

Recall...

 

If you are not familiar with the conditional branch command, the image below shows all of the built-in conditions that are available for users.

 

conditionalbranchinput1.jpg

 

It also comes with a script box that has a character limit of 10000, which is enough for almost anything anyone would need to do with a script call.

 

Ideally, if you're working with any event (map event, troop event, common event), and your script uses conditions, you want to use a conditional branch command.

 

Script Parsing

 

The conditional branch command is command 111 in the game interpreter. You can look at it in your script editor to see how it is evaluated. Typically, I would just copy this code into my own method and adapt it to suit my own needs.

 

To actually get the command, you will need to parse the event list. Depending on what type of event you're working with, accessing the list would be a bit different, but once you have access to the list, you would simply iterate over each command as follows to find the command you want:

list.each do |cmd|
  if cmd.code == 111
    # do something with the conditional branch command
  end
end
Examples

 

Here are a couple scripts that use conditional branch commands for input.

Logical Expressions

 

The conditional branch command allows you to ask questions like

  • Is Actor 3 a Soldier class?
  • Does the party have a Hand Ax in their inventory
Which can be evaluated easily. However, what happens when you want to ask more complex questions such as
  • Is Actor 3 a Soldier AND is Actor 3 wearing a Hat?
  • Is switch 1 on OR Switch 2 on?
These are separate conditions joined one or more of the following logical operators:
  • AND
  • OR
  • NOT
This is very easy to accomplish using script calls, but remember the point is to make it easy for users who may not be proficient in ruby. Some users may not even have any idea how programming works.

 

The following rules are proposed for logical expressions using conditional branch commands. Here are some examples to illustrate it:

 

1. One command represents one condition.

2. Every pair of commands is joined by a logical operator.

3. Two commands with the same indent are joined using OR

 

conditionalbranchinput3.jpg 

 

4. Two commands with a nested indent are joined using AND

 

conditionalbranchinput4.jpg 

 

5. All conditions with non-decreasing indents are grouped together.

 

 conditionalbranchinput5.jpg 

 

Condition 0 = indent 0

Condition 1 = indent 1, therefore they are grouped together

Condition 2 = indent 0, so this is the start of a new group

Condition 3 = indent 1

 

6. All conditions are parsed recursively. Parentheses are based on groups

 

conditionalbranchinput6.jpg

 

The last image basically summarizes all of the rules. It may take some time to understand it, but if you think of it as a regular boolean expression, it should become clearer:

(a AND (b OR c))
We are simply applying each rule one by one as you go down the conditions, grouping them based on the non-decreasing indentation rule.

 

Note that negation is not shown here. This is because the default conditional branches do not support negation.

 

Ending

 

With this in mind, you should be able to provide your users with a much easier way to specify conditions if your script needs it.

 

Originally posted at Hime Works.

Edited by Tsukihime
  • Like 2

Share this post


Link to post
Share on other sites

I may have to read this a few times more, since I still have problems knowing when and when not to nest conditionals.

Share this post


Link to post
Share on other sites

I usually just think of it like this:

 

If you require both conditions to be true, nest them.

If you require only one to be true, don't nest them.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

How would a script call look if you are wanting to use a conditional branch that checks if the tool needed is equipped? for RGSS3.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted