Staredit Network

Staredit Network -> Concepts -> The "if" Statement With StarCraft Triggers
Report, edit, etc...Posted by DrunkenWrestler on 2005-01-04 at 23:02:10
I just thought of a way to do if statements using StarCraft triggers. Sorry if this is actually redundant.

Let's say I want a marine to say, "I want a beer" and if and only if player one has 10 minerals, the marine will say, "And a hooker too." Here is some pseudocode to for that trigger:

CODE
CONDITION:
- Player 1 Brings at least 1 Terran Marine to Locatoin 'Bar'
ACTION:
- Display Text Message: "MARINE:     I want a beer"
- Wait 3000 miliseconds
- Set Switch 1
- Create 1 Vespene Tank for player 7 at 'Bar'


CODE
CONDITION:
- Switch 1 is set
- Player 1 accumulates 10 or more ore
ACTION:
- Display Text Message: "MARINE:     And a hooker too."
- Wait 3000 miliseconds
- Create 1 Sarah Kerrigan for player 7 at 'Bar'
- Clear Switch 1


The marine will say the extra line if and only if player 1 has 10 minerals. This is pretty simplifed, but I'm sure you can do more complex things, such as trigger an entire series of events if a "condition" within an action is met.
Report, edit, etc...Posted by chuiu on 2005-01-04 at 23:13:51
Dude, essentially EVERY trigger is an if statement. Even ALWAYS and NEVER are if statements in the view of Starcraft.

If (true) then ... in trigger form is:

Conditions:
Always.
Actions:
...

If (false) then ... in trrigger form is:

Conditions:
Never.
Actions:
...

It's just a matter of translation from trigger language to how Starcraft interprets it.
Report, edit, etc...Posted by Heimdal on 2005-01-05 at 00:03:04
Very true. The notion Drunk was trying to illustrate was nested if statements, which aren't really possibly without using multiple triggers as he showed. In most cases it wouldn't even be necessary to waste a switch on this since you could just copy the conditions from the original trigger. If the actions of the first trigger changed the conditions that the trigger checked for, then you would need to use a switch.
Report, edit, etc...Posted by idoL on 2005-01-05 at 00:58:52
His trigger is more of a "true, if [action]" more then a regular statement.
Report, edit, etc...Posted by NerdyTerdy on 2005-01-05 at 15:03:39
Drunken you need preserve trigger if you ever want it to happen more than once and maybe something like if they don't already have a beer in conjunction with the preserve trigger but I guess that was just an example anyhow yeah it is sort of old news but at least you figured it out on your own smile.gif.
Report, edit, etc...Posted by Mini Moose 2707 on 2005-01-05 at 19:15:49
Nothing Clears Switch 1 if they don't have ten minerals. They can bring the Marine to the location, leave, then get 10 minerals in some totally distant place.
Report, edit, etc...Posted by MapUnprotector on 2005-01-05 at 20:29:23
You can do lots of things like Ifs, ands, and ors but it just takes more than one trigger.
Report, edit, etc...Posted by DrunkenWrestler on 2005-01-06 at 18:51:09
QUOTE(Mini Moose 2707 @ Jan 5 2005, 07:15 PM)
Nothing Clears Switch 1 if they don't have ten minerals. They can bring the Marine to the location, leave, then get 10 minerals in some totally distant place.
[right][snapback]119804[/snapback][/right]

I guess you could clear it in the first trigger then. This was a pretty rough draft.
Report, edit, etc...Posted by Neiji on 2005-01-06 at 18:59:47
And you can't create a vespene tank.
Report, edit, etc...Posted by chuiu on 2005-01-07 at 01:02:57
There were like 5 errors with his actual triggers but that wasn't the whole point of his post. He was simple trying to demonstrate something.
Next Page (1)