2. Display a message
Let your first spell leave a message in the workshop log. The log records workshop information and messages from your spells. Seeing your message confirms that your instruction ran.
Prepare the spell
Open Script in the game. Save any existing spell first. Stop a running script before editing.
Copy this complete example into the editor. Replace the existing contents rather than appending another autonomous spell.
public class Program : ArcaneProgram
{
public void OnStart()
{
Workshop.Log.Write("Hello!");
}
}The outer lines provide the structure the game needs to run your autonomous spell. Leave them unchanged for now. Focus on Workshop.Log.Write("Hello!");.
Run and check
- Select Save to keep the spell.
- Select Compile to check how it is written.
- If there are no errors, select Run.
- Open the log and find Hello!
Saving alone does not execute the instruction. If compilation reports an error, compare the indicated line with the example before compiling again.
Change the message
Workshop.Log.Write writes text to the log. Text enclosed in double quotation marks is called a string. This example displays Hello! without the quotation marks.
Change Hello! to Welcome!, then save, compile and run again. Keep the quotes, the surrounding parentheses and the final semicolon. Use ordinary ASCII punctuation.
Exercise
Change the first example to display Ready. Change only the text inside the quotation marks.
Show example solutionHide example solution
public class Program : ArcaneProgram
{
public void OnStart()
{
Workshop.Log.Write("Ready");
}
}A new Ready entry confirms the change. If older messages remain in the log, look for the newly added entry.
