Let's say you wanted to send a message to only gods. In that case, you would use an If... Then statement You want to say something like, "If the Player is a God Then PlayerMessage." The code turns out something like this:
FUNCTION Main(Player as LONG, Command as STRING, Parm1 as STRING, Parm2 as STRING, Parm3 as STRING) AS LONG
If GetPlayerAccess(Player) > 0 Then 'If the player's god access is greater than 0 Then
PlayerMessage(Player, "Hello god person!", BrightGreen)
End If
Main = Continue
END FUNCTION
Now the script only works for gods.
The GetPlayerAccess function takes one parameter: the player of whom you want to find the access. It gives back, or returns, the god access of that player. Mortals have an access of 0 and gods have an access greater than 0, so by testing to see if the player has access greater than 0, the script knows whether the player is a god or not. If the player is a god, then the script runs everything after the If statement and continues on after the End If. If the player is a mortal, the script just jumps directly to End If, skipping everything in between.
There are 6 comparison operators. You can use any of them in an If statement:
| > | Greater Than |
| < | Less Than |
| >= | Greater Than or Equal To |
| <= | Less Than or Equal To |
| = | Equal To |
| <> | Not Equal To |
If statements can also be paired with an Else. If the condition in the If statement is not met, the script jumps to the Else instead of the End If. If the condition is met, the script jumps over the Else to the End If. For example:
FUNCTION Main(Player as LONG, Command as STRING, Parm1 as STRING, Parm2 as STRING, Parm3 as STRING) AS LONG
If GetPlayerAccess(Player) > 0 Then 'If the player's god access is greater than 0 Then
PlayerMessage(Player, "Hello god person!", BrightGreen)
Else 'Otherwise
PlayerMessage(Player, "Hello foolish mortal!", BrightGreen)
End If
Main = Continue
END FUNCTION
If the player is a god the script tells them, "Hello god person!" Otherwise it says, "Hello foolish mortal!"
Now let's change the script once again so that it only works for mages and dark mages (classes 1 and 2). In English the script would be like, "If the Player is Class 1 or Class 2 Then PlayerMessage." It turns out that MBSL lets you use the word Or in this case:
FUNCTION Main(Player as LONG, Command as STRING, Parm1 as STRING, Parm2 as STRING, Parm3 as STRING) AS LONG
If GetPlayerClass(Player) = 1 Or GetPlayerClass(Player) = 2 Then 'If the player's class is 1 or 2 Then
PlayerMessage(Player, "You can cast spells.", BrightGreen)
End If
Main = Continue
END FUNCTION
Unlike in English, you need to include GetPlayerClass(Player) after every Or so that MBSC knows what you're comparing. And works in a similar way to Or.
You might notice that in some scripts, people also use & and |. & is simply the same thing as And and | is the same thing as Or. C++ programmers might recognize these symbols.
Select Case statements can be used if you want different things to happen to many different people. (C++ and Java programmers call these switch statements.) Here, I will use a Select Case statement to send different messages to different classes:
FUNCTION Main(Player as LONG, Command as STRING, Parm1 as STRING, Parm2 as STRING, Parm3 as STRING) AS LONG
Select Case GetPlayerClass(Player)
Case 1 'Mages are class #1.
PlayerMessage(Player, "You are a mage.", BrightGreen)
Case 2 'Dark mages are class #2.
PlayerMessage(Player, "You are a dark mage.", BrightGreen)
Case 6 'Clerics are class #6.
PlayerMessage(Player, "You are a cleric.", BrightGreen)
Case 9 'Necromancers are class #9.
PlayerMessage(Player, "You are a necromancer.", BrightGreen)
End Select
Main = Continue
END FUNCTION
I could have written this as a bunch of If GetPlayerAccess(Player) = number Then but this is much cleaner and simpler.