📚
YAGPDB
  • YAGPDB Coding System - Documentation
  • Getting Started
  • Useful Functions
  • Primary Level
    • The Dot and Variables
      • User
      • Guild / Server
      • Member
      • Channel
      • Message
      • Reaction
      • Time
    • Custom Types
    • Functions
      • Type Conversion
      • String Manipulation
      • Math Functions
      • Message Functions
      • Mentions
      • Role Functions
      • Current User
      • Miscellaneous
      • ExecCC
    • Conditional Branching
  • Intermediate Level
  • Database
  • Range Action
  • With Action
  • Custom Embeds
  • Advanced Level
    • Using RegEx
  • Custom Commands Examples
    • Texas Hold'em
Powered by GitBook
On this page
  • Preface
  • Function

Was this helpful?

  1. Primary Level

Conditional Branching

Useful when there are multiple choices

Preface

Branching using if action's pipeline and comparison operators - these operators don't need to be inside if branch. if statements always need to have an enclosing end.

Comparison operators always require the same type: i.e comparing 1.23 and 1 would throw incompatible types for comparison error as they are not the same type (one is float, the other int). To fix this, you should convert both to the same type -> for example, toFloat 1.

Function

Case

Example

if

{{if (condition)}} output {{end}}

Initialization statement can also be inside if statement with conditional statement, limiting the initialized scope to that if statement. {{$x := 24}} {{if eq ($x := 42) 42}} Inside: {{$x}} {{end}} Outside: {{$x}}

else if

{{if (condition)}} output1 {{else if (condition)}} output2 {{end}}

You can have as manyelse ifstatements as many different conditionals you have.

else

{{if (condition)}} output1 {{else}} output2 {{end}}

not

{{if not (condition)}} output {{end}}

and

{{if and (cond1) (cond2) (cond3)}} output {{end}}

or

{{if or (cond1) (cond2) (cond3)}} output {{end}}

Equal: eq

{{if eq .Channel.ID ########}} output {{end}}

Not equal: ne

{{$x := 7}} {{$y := 8}} {{ne $x $y}} returns true

Less than: lt

{{if lt (len .Args) 5}} output {{end}}

Less than or equal: le

{{$x := 7}} {{$y := 8}} {{le $x $y}} returns true

Greater than: gt

{{if gt (len .Args) 1}} output {{end}}

Greater than or equal: ge

{{$x := 7}} {{$y := 8}} {{ge $x $y}} returns false

Example:

  • It will only execute the first one that matches the condition you want.

{{$x := 13}}
{{if ne $x 1}}
Will execute this one.
{{else if eq $x 13}}
Will not execute this one.
{{else}}
Will not execute this one.{{end}} 
  • If you write the codes like this, it will execute all parts.

{{$x := 13}}
{{if ne $x 1}}
Will execute this one.{{end}}
{{if eq $x 13}}
Will execute this one.{{end}}
{{if gt $x 1}}
Will execute this one.{{end}}
  • You can also define the variable like the following one.

{{if ge ($x := randInt 10) 4}}
{{$x}} is greater than 4
{{else}}
{{$x}} is smaller than 4
{{end}}

PreviousExecCCNextDatabase

Last updated 4 years ago

Was this helpful?

When you use if-else functions, it will only execute the first one that matches the condition you want even if it matches multiple conditions. Example .

here