NetStorm Wiki

Editing and making your own campaigns Getting Started,
Advanced Editing 1.Images | 2.Links and E-mails | 3.More [Options] Sections. 4.Options | 5.More [Header] Variables Header Variables | 6.Changing Text Colors | 7.Sacrificing for Knowledge | 8.Branching using MissionBegin | 9.Using denySalvage | 10.Outposts in Your Campaign | 11.Branching with MissionFork | 12.The Tell Command | 13.Creating Menus with $Menu | 14.Formatting Text and Graphics | 15.The $Timeout event | 16.The $OnExit event | 17.adding a DEMO to your Campaign | 18.Re-positioning the Text Window (with $MoveDialog)| 19.Timing with [@ ] | 20.Using the Debug Hotkey | 21.Moving the screen window with $View| 22.Variable basics | 23.IF/THEN Conditionals | 24.The $PlaySound command | 25.Netstorm Command List

view this alone

The If/Then Conditional

Conditionals in NS Script

Yes, Netstorm does have an If/Then conditional. And yes, you can do lots and lots of neat stuff with this. But first, you gotta learn the syntax, and the known limitations before you should use this in your Campaigns...

Simply Put:

When we make a decision, we either choose a Yes decision (Yes, I want an IceCream! With Lots and Lots of Gooey stuff on it!), or a No decision. (No, I don't want an IceCream. Too fattening!). We may change our mind later on, but ultimately every decision we make comes down to Yes (take action) or No (take another action).

Well, the if/then in NS script is very similar in operation. You can have something be performed when a condition is TRUE (or YES), or you can have something be performed when a condition is FALSE (or NO - or NOT TRUE).

Ahh... the gears are starting to turn now. You're probably saying I've used NOT before in Netstorm. And you have, if you've used the ainAbility="" command (Remember things such as ai2Ability="!CAPTURE_ENEMY_PRIEST"). Well, you can use ! with conditionals, also.

So, this gives us two flavors for the If/then conditional: True and false. 

A Variable by any Other Name is Still a Variable:

At this point, what we know of the conditional, is that the if/then is almost certainly used with flags. What the heck is a flag, you say? Well, for programmers, it's a variable that is either TRUE (1), or FALSE (0).  Flags are great for keeping track of allys, Tech, etc. in Netstorm Missions.

Say you have an ally in your Campaign. You want to have something to indicate whether the ally is dead or alive. AHA! Lets try using a flag for this! So, you could set up a variable named sw_allyDead=0. This would indicate that the ally is NOT dead. If later in the Campaign your ally dies, then you would set sw_allyDead=1.

Yeah, but how do we use the if/then along with flags to do some neat stuff? Well, let's take a look at if/thens:

Putting it All Together:

The if/then is almost always used after the [Options][A.] in the english file. And for that reason, the command is enclosed in <  >. The basic syntax for the if/then is:

<?{VariableName}>Do something that's true</?>

Wow. Is that syntax strange, or what? Let's look more closely at the statement. The ? is the IF part of the command. VariableName should be the flag that keeps track of stuff for us. Do something that's true can either be text that's displayed or another command that's can be executed when the conditions of the conditional are met (TRUE or NOT TRUE). The </?> at the end indicates to end the command at this point. This implies that the if/then statement can be multi-lined. This is true.

Back to our example. Let's have our story change in our mission depending on whether our ally dies or not. You want this to happen during the [Succeeded] or [Failed]. Let's see how to do it. AI2 is the ally, while AI3 is the enemy in this example:

....... all normal header stuff.....

<$Config,sw_enemyName="Lord of ~yLIGHT~.">
<$Config,sw_allyName="Lord ~k~BFOUL~.">

<h2>                            ~yTO WAR!</h2>
Another day another war! You call to your friend, {sw_allyName}. <i>"Hey there good buddy! Let's attack those pesky and sickeningly nice {sw_enemyName} <i>Priests!"~.

<p>{sw_allyName}, eager to attack and destroy anything that's good or nice, immediately agrees!

$Button=TO WAR,DoNothing,0

Oh, no! Your ally {sw_allyName}, has been sacked! You will make the enemy pay for this!

$Button=FIGHT ON!,DoNothing,0

Horrah! You <?!{sw_allyDead}>and your ally</?> are triumphant! You <?!{sw_allyDead}>both </?>have shown the enemy who <?{sw_allyDead}>is</?><?!{sw_allyDead}>are</?> the real ruler<?!{sw_allyDead}>s</?> of Netstorm!

<p><?{sw_allyDead}>A moment of silence as you greive of your loss of your friend. </?>

<?!{sw_allyDead}>The Furies are well pleased with you and {sw_allyName}'s easy victory. To celebrate, they grant you the power of wind!




What a nightmare. You <?{sw_allyDead}>and your ally, {sw_allyName}, </?>have been sacrificed!

<p>The furies give you another chance, as they ressurect you <?{sw_allyDead}>and your ally, </?>from the depths of Hell down below!

$Button=Retry Mission,MissionBegin,{mission.Filename}

What the heck is all that <?!.... </?>, etc etc. Yeah, I know it looks pretty confusing. And it's a lot of code to digest in one sitting. But it's actually not that bad. Look at everything with a color of pinkish-red. This part of the code will only occur when sw_allyDead=1 (or the ally is DEAD). The code that's in green, will only execute when sw_allyDead=0 (meaning that your buddy is alive).

How do we make our buddy alive? In the [Init] routine. We make the ally flag set to 0. Later, if our buddy gets sacked we change the sw_allyDead flag to a 1. Now, in this example, everything will continue, even if your friend gets sacked, until either you win the game, or you lose the game. Then we use a lot of if/then's to change the story.

Couple of things to note. See the last line? See the MissionBegin,{Mission.Filename}? This will cause NS to restart whatever fort file that was just played. Pretty neat. Also, when you win, another variable is set: sw_weapon1=1. In this example, I would use this flag to show other parts of code in the next mission that the player has the Crossbow. But that another subject and another Lesson....

So what happens when we run it? Well, there can be quite a few different outcomes. But first, the intro screen will always stay the same:


Ok, we made our point with getting the player's interest. Now let's see what happens when the Mission continues...

How many different things can happen? Well we can

  • lose our ally and lose the game
  • lose our ally but win the game
  • lose the game, but the ally is ok
  • win the game with our ally alive

If we lose, we may either have or not have our ally alive. Below, the screen on the left shows what will be displayed if we both get sacked. On the right, is the screen that's displayed if the player gets killed, but the ally survives.

File:IfThenEx2.jpg   File:IfThenEx3.jpg

Now, onto the win conditions. We can either win, with our ally or win without our ally (sniff sniff). Below, is shown on the left without the ally making it, and on the right, we did everything right in the mission and our buddy was saved:

File:IfThenEx5.jpg    [[Image:IfThenEx4.jpg[]]

Hmm... interesting. Lots of possibilities. But there's more.

Combining to form AND and OR:

You can combine if/then statements and flags to give you more options! I'll only touch on this here, since this is another section I'll be exploring very soon ( in an advanced editing section titled Operators101).

You can have this, which combines if/then and flags to make an AND condition. Notice that the only way the code in green will run, is when both flag1 and flag2 are TRUE (or 1):

<?{flag1}><?{flag2}>Both flag1 and flag2 have to be 1 to show this</?></?>