3. Instruction order
A spell specifies both what to do and the order to do it in. Place two message instructions together and watch the order in which they appear in the log.
Execute from top to bottom
public class Program : ArcaneProgram
{
public void OnStart()
{
Workshop.Log.Write("Start");
Workshop.Log.Write("Finish");
}
}The autonomous spell writes Start, then Finish. Within this block, the upper instruction executes first.
A written instruction like each of these is called a statement. Each ends with a semicolon. Starting a new line and ending a statement are different things.
Read a block
The opening brace after OnStart() and its matching closing brace enclose the startup instructions. Put the statements you change inside this block.
Spaces at the beginning of a line are indentation. They help you see which block a line belongs to. Braces, rather than spaces, define the actual boundary.
Text from // to the end of a line is a comment. For example, // Start message does not execute. It is a note for someone reading the spell.
Exercise
What message order will you get if you swap the two Write lines? Predict it, then try.
Show example solutionHide example solution
Finish, then Start. The order of statements determines execution, not the meaning of the displayed words.
public class Program : ArcaneProgram
{
public void OnStart()
{
Workshop.Log.Write("Finish");
Workshop.Log.Write("Start");
}
}