In MBSL as in many languages, code is organized into groups called functions. A function takes data as parameters, then performs a specific task using the provided data. This function takes an hour and returns "AM" if it is in the morning and "PM" if it is in the afternoon:
Function AMPM(Hour as Long) as String
If Hour < 12 Then
AMPM = "AM"
Else
AMPM = "PM"
End If
End Function
We call the function by using the name and parameters:
Dim Time as Long
Time = GetHour()
PlayerMessage(Player, "The time is " + Str(Time) + ":00" + AMPM(Time), Yellow)
There is one primary difference between functions and subroutines. Functions return a value, and subroutines don't.
This is a more advanced topic. It will probably be moved under UDTs.
(Note to self: Primitive types are passed by value and UDTs are passed by reference. How Java-esque! Except String is a primitive..)