WarScript API Reference
Native functions available in the global scope
Language
WarScript syntax reference — constructions, data types, and operators.
Basic Constructions
Variables
# plain types
a1 = 123
a2 = "hello world"
# class instance
left_tree_node = new TreeNode [ 1 ]
tree_node = new TreeNode [ 3, left_tree_node, new TreeNode [ 2 ] ]
# array
example_array = { 1, 2, "three", new TreeNode [ 4 ] }
empty_array = {}
Conditions
if a1 > 5 and tree_node :: value == 3
# statements
elif a2 == "hello" or a3 == "world"
# statements
else
# statements
end
print a1 + a2 + tree_node :: value
Import
import "lib/common.ws"
Functions
fun fibonacci_number [ n ]
if n < 2
return n
end
return fibonacci_number [ n - 1 ] + fibonacci_number [ n - 2 ]
end
Loops
# for loop
loop i in 0..10
# statements
end
# with step
loop i in 0..100 by 5
# statements
end
# while loop
loop health > 0
# statements
end
# for-each
loop item in items
# statements
end
# break and next
loop i in 0..10
if i == 5
break
end
if i == 3
next
end
end
Exceptions
class MyException [message]
end
begin
raise new MyException ["Error message"]
rescue error
print error :: message
ensure
print "Always runs"
end
Data Types
Numeric
number1 = 1
number2 = 3.21
number3 = .543
number4 = -1
Text
text = "hello world"
print text{1}
text{1} = "a"
Logical
logical1 = true
logical2 = false
Class
class Lamp [ type, is_on ]
fun turn_on
is_on = true
end
fun turn_off
is_on = false
end
fun set_is_on [ is_on ]
this :: is_on = is_on
end
end
lamp = new Lamp [ "Halogen", false ]
# get/set properties
lamp_is_on = lamp :: is_on
lamp :: type = "Led"
# invoke functions
lamp :: turn_off []
# inheritance
class DerivedClass: BaseClass [ property ]
end
Arrays
items = { 1, 2, "three" }
# get/set by index
value = items{1}
items{1} = 123
# append
items << 3
Null
value = null
NativeObject<T>
fun on_unit_died[unit]
print Unit_get_position[unit]
end
Operators
Operators ordered by precedence (lowest to highest):
| Operator | Symbol | Precedence | Example |
|---|---|---|---|
| Assignment | = | 1 | a = 5 |
| Append to array | << | 1 | array << "value" |
| Logical OR | or | 2 | true or false |
| Logical AND | and | 3 | true and true |
| Parentheses | ( ) | 4 | |
| Equals | == | 5 | a == 5 |
| Not Equals | != | 5 | a != 5 |
| Greater Than Or Equals | >= | 5 | a >= 5 |
| Greater Than | > | 5 | a > 5 |
| Less Than Or Equals | <= | 5 | a <= 5 |
| Less Than | < | 5 | a < 5 |
| Addition | + | 6 | a + 5 |
| Subtraction | - | 6 | a - 5 |
| Exponentiation | ** | 7 | a ** 5 |
| Multiplication | * | 7 | a * 5 |
| Division | / | 7 | a / 5 |
| Floor Division | // | 7 | a // 5 |
| Modulo | % | 7 | a % 5 |
| NOT | ! | 8 | !false |
| Class Instance | new | 8 | new Type [ value ] |
| Nested Instance | :: new | 8 | type :: new NestedType |
| Property Access | :: | 8 | type :: value |
| Cast | as | 8 | type as Supertype |
| Instance Of | is | 8 | type is Supertype |
Global
Attaches and runs a new WarScript by name on the current room.
| Parameter | Type |
|---|---|
scriptName | Text |
Detaches the current script from the room and stops execution.
No parameters
Array<NativeObject<WarmanPlayer>>
Returns an array of all players currently in the room.
No parameters
Plays a one-shot sound effect by name. Only audible if the local player is observing the room.
| Parameter | Type |
|---|---|
name | Text |
NativeObject<EnemySoul>
Spawns a unit soul at the given world position. Returns null if position is invalid.
| Parameter | Type |
|---|---|
position | Array |
NativeObject<Enemy>
Spawns a unit at the given world position.
| Parameter | Type |
|---|---|
unitName | Text |
position | Array |
level | Numeric |
isAlly | Logical |
isElite | Logical |
isSummon | Logical |
Player
Functions that operate on a Player handle.
Awards experience points to a player.
| Parameter | Type |
|---|---|
player | NativeObject<WarmanPlayer> |
exp | Numeric |
Unit
Functions that operate on a Unit handle.
NativeObject<ModifierWrapper>
Applies a modifier by name to a unit. Returns null if the modifier is not found.
| Parameter | Type |
|---|---|
unit | NativeObject<Unit> |
modifierName | Text |
Array<Numeric>
Returns the world position of a unit as an array of [x, y, z].
| Parameter | Type |
|---|---|
unit | NativeObject<Unit> |
Events
Callback functions called by the engine when implemented in your script.
Called when attaching the script to a room.
fun on_attach[]
Event when a player enters the room.
| Parameter | Type |
|---|---|
player | NativeObject<WarmanPlayer> |
fun on_player_enter_room[player]
Event when a unit dies in the room.
| Parameter | Type |
|---|---|
unit | NativeObject<Enemy> |
fun on_unit_died[unit]
Called each simulation tick. Includes the deltaTime of the current tick.
| Parameter | Type |
|---|---|
dt | Numeric |
fun tick[dt]