Scripting First Steps – Arma Reforger
Welcome to Enforce Script! This guide will get you writing and testing your first lines of code in 5 minutes.
Requirements
- Arma Reforger Tools (Arma Reforger Workbench) installed via Steam
- That's it!
Open Workbench and Remote Console
- Launch Enfusion Workbench from Steam (Arma Reforger Tools)
- Click on the Script Editor icon or select it from the menu
- If the Remote Console window is not visible, open it from the menu
- Click on the Remote Console and Output tabs at the bottom to switch to the appropriate view
- You are ready to start coding!
First Line of Code
Type the following in the Remote Console and click the Run button at the top of the remote console panel:
The Print method prints (as its name states) the provided arguments into the log console:
You did it! You just wrote your first Enforce Script code. The text appears in the console output.
PrintFormat allows for printing a string with arguments:
Basic Maths
Try these commands one by one in the Remote Console:
The console shows: 15, 60, 25.
Variables
Variables let you store and reuse values:
Try changing the number and run it again!
Common variable types:
- int - whole numbers (1, 42, -5)
- float - decimal numbers (3.14, 10.5)
- string - text ("Hello", "Arma")
- bool - true or false
Decisions
Try changing health to different numbers!
Arrays
Arrays can be seen as lists that store naught to multiple values of the same type:
Loops
For
A for loop repeats instructions a specific number of times:
Foreach
A foreach loop goes through all array items:
The index can also be obtained this way:
A First Mini-Program
Combine what you learned! Copy this entire block and run it:
Quick Reference Card
| Category | Code | Description |
|---|---|---|
| Output | Print("text"); |
Shows text in console |
| Variables | Stores a whole number | |
| Stores a decimal number | ||
| Stores text | ||
| Stores true/false | ||
| Arrays | Creates a list | |
myArray.Insert(value); |
Adds item to list | |
myArray.Count(); |
Gets list size | |
| If/Else | if (condition)
{
} |
Do something if true |
else
{
} |
Do something if false | |
| Loops | Repeat 10 times | |
| Execute for each item | ||
| Math | + | Add |
| - | Subtract | |
| * | Multiply | |
| / | Divide | |
| Compare | == | Equal to |
| != | Not equal to | |
| > | Greater than | |
| < | Less than | |
| >= | Greater or equal | |
| <= | Less or equal |
Common Mistakes
| Incorrect | Correct | Explanation |
|---|---|---|
| print("hello") | Print("hello") | Capital P in Print |
| int x = 5 | int x = 5; | Missing semicolon |
| if (x = 5) | if (x == 5) | Use == for comparison, = for assignment |
| int firstElement = myArray[1]; | int firstElement = myArray[0]; | Arrays start at 0, not 1 |
| string name = John | string name = "John" | Text needs quotes |
Exercises
The following challenges help in practicing and understanding scripting.
Temperature Converter
Create a program that converts 25°C to Fahrenheit.
Countdown
Create a countdown from 10 to 0, then print "Launch!".
Squad Filter
Print only the soldiers with health above 50 from two arrays (names and health values).
Troubleshooting
Console will not open?
- Make sure the Script Editor is opened in Workbench
- Look for the Remote Console panel - if hidden, open it from the menu
- Ensure Workbench is properly installed via Steam (Arma Reforger Tools)
Code does not work?
- Check for missing semicolons ;
- Make sure quotes match: "text"
- Check spelling and capitalisation (casing matters: print("ok"); is different from Print("ok");)
- Look for error messages in red
Getting errors?
- Read the error message - it often tells you what is wrong
- Click the error message and check reported line number(s)
- Make sure all open brackets { } are closed
See Also
Reference Documentation:
- Scripting Values - All data types in detail
- Scripting Conventions - Bohemia Interactive coding standards
- OOP Basics - Object-oriented programming fundamentals