Clan UFW

Warcraft 3 USEast Clan for Fate / Another
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 [Tutorial | Triggering Basics #1] How to use the IF, AND and OR conditions

View previous topic View next topic Go down 
AuthorMessage
l46kok
Fate Another Developer


Posts : 1673
Join date : 2009-08-01
Age : 29
Location : Laramie

PostSubject: [Tutorial | Triggering Basics #1] How to use the IF, AND and OR conditions   Sat Aug 01, 2009 4:37 pm

This tutorial is for entry-level trigger writers. This assumes that you have a minor background in writing triggers.

L46kok's Tutorial #1 : How to use the How to use the If, And and Or conditions

Ah, the condition structures. What can you possibly accomplish without it? If there is something you have to do sometime in your life, it's to make choices. You are given what choices to make based on what condition. The programmers were nice enough to pertain those conditions even on World Editor (Abbreviated as WE) along with the fact that it is YOU who gets to create those.

So what is a condition structure? Well taken from the Wikipedia's dull yet accurate explanation:

Quote :
In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified condition evaluates to true or false.
Source : http://en.wikipedia.org/wiki/Conditional_statement

If this didn't make sense, do not be intimidated - because this means you are normal. If you DID make any sense out of this, then either you are a IQ 180 genius, you've had some background in a programming language or you need to go see a doctor right away.

But to elaborate the definition above in English, this is saying
Perform action B if condition A is true. This will make more sense as we will talk about the specifics of IF-THEN-ELSE condition




1.IF-THEN-ELSE Condition

IF-THEN-ELSE condition is almost self explanatory. Here is the basic structure of it:

If Condition A is True
Then
_____Perform Certain Action(s)
Else
_____Perform Certain Action(s)

Basically, from the condition structure, if whatever is evaluated comes out to be true in the IF condition, then it jumps to the actions under THEN. However, supposing the evaluated result was false in the IF condition, then it jumps to the actions under ELSE. Here is an example of how it actually looks like in WE:



An extremely simple condition regarding the controller status of player 1. If Player 1 is a human player, then display "P1 is Human". Else (If not true), display "P1 is computer". By the way. you don't have to put actions for both THEN and ELSE. Only putting your actions on either THEN or ELSE is acceptable.





2.OR Condition

Or condition only evaluates TRUE or FALSE at the end of the result. It does not perform any actions by itself. This is the structure of it:


Evaluate if any one of the following conditions are true
_____Condition A
_____Condition B

Here is an example of it:



Notice how I put the OR condition under the IF condition. As I told you, the OR condition only returns true or false based on the condition given in it. So in this case, if the OR condition turns out to be true, then it performs the actions under THEN. If not, then it goes under ELSE.

In other words, if player is EITHER a HUMAN or a COMPUTER player, then it displays : "P1 is HUMAN or CPU player". Otherwise, it displays "P1 is Neither". You might be saying "What the fuck? How can it be neither?" but actually this case is possible - if P1 was either neutral (creeps) or rescuable, then it is not considered as a CPU player.




3.AND Condition

Just like OR condition, AND condition only evaluates TRUE or FALSE at the end of the result. It does not perform any actions by itself. This is the structure of it:


Evaluate if all the following conditions are true
_____Condition A
_____Condition B

Here is an example of it:



This should be self-explanatory at this point - If P1 is a human player AND he is currently playing in the game, then display "Player 1 is a human" and "Player 1 is playing". Otherwise, do nothing.

Now smart people might have noticed something very contradictory : What if you don't put either AND or OR condition under the IF condition? then what happens? In other words, if you have something like:



Then what's the end result? Turns out that the if condition is an AND condition by default, so it will only jump to THEN actions if all the conditions under the IF condition are true.

What exactly is the point of using an AND condition then? Well, one reason is that you could have an OR condition, then an AND condition inside it, like this:


Under the actions, the full text is "P1 is a human and playing or a computer"



And that concludes the explanation of the condition structure. There is absolutely nothing hard about this but you should always practice on your own to master it. Please leave any questions or comments so I can further improve this tutorial. Thanks for reading.
Back to top Go down
View user profile http://clanufw.darkbb.com
ZeiZou

avatar

Posts : 153
Join date : 2009-08-18
Age : 22
Location : Somewhere~

PostSubject: Re: [Tutorial | Triggering Basics #1] How to use the IF, AND and OR conditions   Wed Sep 16, 2009 7:05 pm

Very nice Tutorial, Although I never had a problem using conditions before.
Back to top Go down
View user profile
 
[Tutorial | Triggering Basics #1] How to use the IF, AND and OR conditions
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Unity 5 Basics Tutorial
» Great Tank and Weathering tutorial
» Power Sword Tutorial (with more to follow)
» Gaming basics and our responsibility
» Instant Mold Tutorial

Permissions in this forum:You cannot reply to topics in this forum
Clan UFW :: Warcraft 3 :: Map Making-
Jump to: