Title: Conditional equations problem
Last modified: November 22, 2019

---

# Conditional equations problem

 *  [Angelo De Lorenzo](https://wordpress.org/support/users/angelo_de_lorenzo/)
 * (@angelo_de_lorenzo)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/)
 * I’m creating a rugby league.
    On the player’s performance I created the variables“
   t” (goals made) and “ms” (goals conceded). On event results I created an offensive
   bonus called “bo” and a defensive bonus called “bd”. With the “bo” I have no 
   problems, I set the equation t >= 4. So if a team scores 4 or more goals it takes
   1 offensive bonus. On “bd” if the team with less goals has scored only one goal
   less than the other team the losing team must take 1 defensive bonus. I set the
   following equation, (ms – t) = 1. This doesn’t work because in the results of
   the event on “bd” I always find 0. What am I doing wrong? Am I misinterpreting
   the sign “=” ?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/#post-12179251)
 * Hi!
 * Thanks for reaching out!
 * Let’s translate this rule into a conditional logic. Breaking it into pieces:
 * “If the team with less goals”
    So we need a conditional check: ( ms > t ) Or 
   if this team has more goals awarded than made
 * ” has scored only one goal less than the other team”
    This is almost like you
   wrote: ( (t – ms) = 1 ) Otherwise, it’ll always be negative one or less
 * “the losing team must take 1 defensive bonus”
    Now we just glue it all together:
   bd = ( ms > t ) * ( (t – ms) = 1 )
 * Let’s try this and let us know how it works for you.
 * Thanks!
 *  Thread Starter [Angelo De Lorenzo](https://wordpress.org/support/users/angelo_de_lorenzo/)
 * (@angelo_de_lorenzo)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/#post-12180314)
 * Unfortunately I always get zero as a result of the BD.
    In the event I set: Team1
   4t and 3ms Team2 3t and 4ms
 * The result:
    Team1: BO = 1, BD = 0. Team2: BO = 0, BD = 0.
 * I specify that I am using the free version 2.6.20
 * Checking on modules/sportspress-conditional-equations.php on line 80 I see that
   it does not handle the operation suggested by you (as it did not manage the one
   I created).
 * Code:
 *     ```
       // Find all parentheses with conditional operators
       $re = '/([^[\(|\)]*[<=>][^[\(|\)]*)/';
       if ( preg_match_all( $re, $equation, $matches ) ) {
       foreach ( $matches[1] as $match ) {
       ```
   
 * etc…..
 * In this way it sees only the first equation ms>t, it does not handle the second
   operation.
 * Here you can see the evidence more clearly:
    [LINK TO PHP LIVE REGEX SCREENSHOT](https://lh3.googleusercontent.com/-VnbMsy4m7Ns/Xd5HMVJydtI/AAAAAAAAVCA/7Y-mMr5Kv80r8qU0iM3qZEhI9u-qQ1HRgCK8BGAsYHg/s0/sportspress-conditional-eq.jpg)
 *  Plugin Contributor [Savvas](https://wordpress.org/support/users/savvasha/)
 * (@savvasha)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/#post-12181746)
 * Hi [@angelo_de_lorenzo](https://wordpress.org/support/users/angelo_de_lorenzo/),
 * Maybe the double `()` confuses the “system”. Can you try to create a variable
   like the following:
    `var = t – ms` and then use something like: `bd = ( ms >
   t ) * ( var == 1 )`
 * Thanks,
    Savvas
 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/#post-12181866)
 * Hi Angelo!
 * Another option is debugging each individual component. For example, set
    bd =
   ms > t
 * Check if it’s one for losing team. Then
    bd = ( (t – ms) = 1 ) or the var version
   Savvas suggested, this shows if the last part is correct.
 * Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Conditional equations problem’ is closed to new replies.

 * ![](https://ps.w.org/sportspress/assets/icon-256x256.png?rev=1252005)
 * [SportsPress - Sports Club & League Manager](https://wordpress.org/plugins/sportspress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sportspress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sportspress/)
 * [Active Topics](https://wordpress.org/support/plugin/sportspress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sportspress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sportspress/reviews/)

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [configuration](https://wordpress.org/support/topic-tag/configuration/)
 * [equal](https://wordpress.org/support/topic-tag/equal/)
 * [Equations](https://wordpress.org/support/topic-tag/equations/)

 * 4 replies
 * 3 participants
 * Last reply from: [Roch](https://wordpress.org/support/users/rochesterj/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/conditional-equations-problem/#post-12181866)
 * Status: not resolved