-
-
Notifications
You must be signed in to change notification settings - Fork 17
Logic
The next topic will be about flow control and loop, but in order to understand them, you need to know how logic work. What logic is that, to simply put, some condition. For example, you can have such condition like 1 > 5. Is it a valid statement or invalid statement? Answer is invalid. Because 1 is definitely smaller than 5 right? This comparison will evaluate to false, and this kind of value is called boolean.
Boolean is special kind of data type, and it has only two values: true and false
comparison | boolean |
---|---|
num1 > num2 | if num1 is bigger than num2, this is true, otherwise false |
num1 < num2 | if num1 is smaller than num2, this is true, otherwise false |
num1 >= num2 | if num1 is bigger or equal to num2, this is true, otherwise false |
num1 <= num2 | if num1 is smaller or equal to num2, this is true, otherwise false |
num1 == num2 | if num1 is same as num2, this is true, otherwise false |
string1 == string2 | if string1 is exact match of string2, this is true, otherwise false |
num1 != num2 | if num1 is not same num2, this is true, otherwise false |
string1 != string2 | if string1 is not exact match of string2, this is true, otherwise false |
Most of the time, you will need to check more than one logic at the same time. For example, you might want to check if player's X position is same as 5 and also Y position is same as 10. How to do that? Use logical operators. You have only two options: &&(AND) and ||(OR).
AND operator checks the condition on its left and right, and will check if both left and right condition is valid. For example, X == 5 && Y == 10 will first check if X == 5 is valid, Y == 10 is valid, and check if both conditions are valid as well. The result is condition; Which means you can add up as much as possible AND operators. X == 5 && y == 10 && z == 20 && player.isSprining() ...
&&(AND) | True | False |
---|---|---|
True | True | False |
False | False | False |
Unlike AND, OR can be useful if you want to see if at least one condition is valid. For example, X == 5 || y == 10 || z == 20 will be valid if at least one of the three conditions is valid. So if X == 5 is invalid, y == 10 is invalid, and z == 20 is valid, then it's still valid.
||(OR) | True | False |
---|---|---|
True | True | True |
False | True | False |
NOT operator simply flip the condition. For example, if it was valid condition and you NOT it, then it becomes invalid. Same thing happens for other way around. if it was invalid and you NOT it, it becomes valid.
!false is same as true, and !true is same as false
!(NOT) | |
---|---|
True | False |
False | True |
Since TR 1.4.1, a new concept called 'short circuit' was added. To simply explain it, lets look at the example:
IF player != null && player.getName() == "wysohn"
ENDIF
before TR 1.4.1, this logic failed because TR always evaluate both left and right operand to work on the Logical Operators. But because Short Circuit feature is added, above statement can work.
Lets think about the case where player was null. The left comparison player != null
becomes false because the variable player is now null, and !=
operator becomes true only when left operand and right operand are not the same. At this time, it's not the case as left is null and right operand is also a null; therefore, it becomes false.
The thing is that, even before &&
operator will work on player.getName() == "wysohn"
, you already know that the result will be false regardless of the result of player.getName() == "wysohn"
. In order for &&
to evaluate into true, both operand must be true, but we already know the left operand is false. This is where the Short Circuit kicks in. Short Circuit checks to see if Logical Operation should be continued depends on the left operand. In our example, the left operand player != null
became false, so TR will just evaluate the whole Logical Operation as false.
Basic Syntax (한) (рус)
1. Getting Started (한) (рус)
S.L. In-game Editor (한) (рус)
List and usage of Triggers / 트리거 목록과 사용 방법:
- Click/Walk Trigger (한) (рус)
- Command Trigger (한) (рус)
- Area Trigger (한) (рус)
- Named Trigger (한) (рус)
- Custom Trigger (한) (рус)
- Inventory Trigger (한) (рус)
- Repeating Trigger (한) (рус)
- List of Executors / 실행자(Executor) 목록
4. Placeholders (한) (рус)
- Using PlaceholderAPI / PlaceholderAPI 사용법
- List of Placeholders / 플레이스 홀더(Placeholder) 목록
5. Conditions (한) (рус)
- Creating Conditions / 조건식 만들기
- Boolean Expressions / 부울 (Boolean) 표현 방법
- Logical Operators / 연산자 사용법
- IF statement / IF 조건문
- Null Checking / Null 검사법
- Switch Case / Switch Case 조건
- Local Variables / 지역 변수
- Global Variables / 전역 변수
S.L. Understanding Exceptions (한) (рус)
- Using Methods / 메소드 사용법
- Special Data Types / 특수한 데이터 형식
- Reading Javadocs / Javadoc 읽기
- Handling Enum / Enum 데이터 처리
- Lambda Expresion / Lambda(람다) 식 사용법
- Creating an empty array / 빈 배열 만들기
- Storing data into array / 배열에 데이터값 저장하기
- Read data from array / 배열에서 데이터 읽기(불러오기)
- WHILE loop / WHILE 반복문
- FOR loop / FOR 반복문
- Iterating Collection / Collection 형식의 변수 순회법
- #BREAK executor / #BREAK 실행자
- #CONTINUE executor / #CONTINUE 실행자
- #CANCELEVENT executor / #CANCELEVENT 실행자
- Setting Sync/Async Mode / 동기, 비동기 모드 전환
- Custom Trigger
- Area Trigger
11. Custom Executors (한) (рус)
12. Plugin Access (한) (рус)
- Check And Use / 플러그인 존재여부 확인
- Get Third Party Plugin / 제 3자 플러그인 불러오기
- Check Eligibility / 호환성 확인하기
- Use the Plugin / 플러그인 사용하기
13. IMPORT Statement (한) (рус)
- Creating new instance / 새 인스턴스 생성하기
- Accessing static method / 종속 메소드 불러오기
- Accessing static field / 종속 Enum 불러오기
14. IS Statement (한) (рус)
- Understanding / 이해하기
- Understanding Instance / 인스턴스 이해하기
- Understanding Superclass / 부모클래스 이해하기
- Understanding Subclass / 자식클래스 이해하기
- Using IS Statement / IS조건연산자 사용하기
15. TRY-CATCH Statement (한) (рус)
- Understanding TRY-CATCH Exception Handling / TRY-CATCH 예외처리 이해하기
16. Interface Casting (한) (рус)
module x.x does not "opens x.x" problem
- List of Custom Events