Skip to content

Functions

Zezombye edited this page May 23, 2020 · 33 revisions

Most function names in OverPy follow these rules:

  1. The function name is camelCased: Create Effect -> createEffect.
  2. Functions that take a player, or player array, as the first argument are member functions:
    Teleport(Event Player, Vector(1,2,3)) -> eventPlayer.teleport(vect(1,2,3)).
    Exceptions are kill(), heal() and damage().
  3. Event-related variables are keywords:
    Event Was Critical Hit -> eventWasCriticalHit.
    They have a special color in the VS Code extension.
  4. Function names are sometimes modified to better reflect how they would be in an actual programming language:
    Control Mode Scoring Percentage -> getControlScorePercentage(),
    Count Of(array) -> len(array).
  5. Functions to get constants such as Hero, Map or Gamemode are replaced by enums:
    Hero(Ana) -> Hero.ANA.

It is advised to rely on the VS Code autocompletion. If you cannot find a function name, decompile the workshop function to get the OverPy name.

Below are the functions that have a special syntax. The italic words indicate arguments; these should be replaced by the appropriate arguments.

Math and Boolean operators

Workshop function OverPy representation
And(op1, op2) op1 and op2
Or(op1, op2) op1 or op2
Not(op1) not op1
Compare(op1, operator, op2) op1 operator op2
Add(op1, op2) op1 + op2
Subtract(op1, op2) op1 - op2
Multiply(op1, op2) op1 * op2
Divide(op1, op2) op1 / op2
Modulo(op1, op2) op1 % op2 1
Raise To Power(op1, op2) op1 ** op2

1 The modulo operator has a higher precedence than the division or multiplication operator.

Variables

Workshop function OverPy representation
Global Variable(variable) variable
Set Global Variable(variable, value) variable = value
Modify Global Variable(variable, Add, value) variable += value 1
Modify Global Variable(variable, Append To Array, value) variable.append(value)
Modify Global Variable(variable, Divide, value) variable /= value
Modify Global Variable(variable, Max, value) variable max= value
Modify Global Variable(variable, Min, value) variable min= value
Modify Global Variable(variable, Modulo, value) variable %= value
Modify Global Variable(variable, Raise To Power, value) variable **= value
Modify Global Variable(variable, Remove From Array By Index, value) del variable[value]
Modify Global Variable(variable, Remove From Array By Value, value) variable.remove(value) 2
Modify Global Variable(variable, Subtract, value) variable -= value 3

1 variable++ can be used if value is 1.
2 Unlike Python, this removes all occurrences of the value in the specified array.
3 variable-- can be used if value is 1.

For player variables, player. is prepended to the variable. For array indexes, [index] is appended to the variable. For example:

Workshop function OverPy representation
Player Variable(player, variable) player.variable
Set Global Variable At Index(variable, index, value) variable[index] = value
Set Player Variable(player, variable, value) player.variable = value
Set Player Variable At Index(player, variable, index, value) player.variable[index] = value
Modify Global Variable At Index(variable, index, Add, value) variable[index] += value
Modify Player Variable(player, variable, Add, value) player.variable += value
Modify Player Variable At Index(player, variable, index, Add, value) player.variable[index] += value

Arrays

Workshop function OverPy representation
Append To Array(array, value) array.append(value) 1 2
Remove From Array(array, value) array.exclude(value)
Index Of Array Value(array, value) array.index(value)
Empty Array(array, value) []
Sorted Array(array, valueRankFunction) sorted(array, lambda elem: valueRankFunction) 3
Filtered Array(array, condition) [elem for elem in array if condition] 3
Is True For All(array, condition) all([condition for elem in array]) 3
Is True For Any(array, condition) any([condition for elem in array]) 3
Array Slice(array, start, length) array.slice(start, length) 4
Array Contains(array, value) array in value
Value In Array(array, index) array[index]
First Of(array) array[0]
Last Of(array) array[-1] 5

1 Literal arrays can also be used: [1,2] will resolve to [].append(1).append(2).
2 The append() function is really extend(), as [1,2].append([3,4]) will result in [1,2,3,4] rather than [1,2,[3,4]]. As such, nested arrays cannot be declared literally.
3 elem represents the Current Array Element workshop value. It must be given a name (usually i or x).
4 Python's slice syntax [start:end] is not used because the workshop slice is start/length instead of start/end.
5 You cannot use the special -1 value at runtime. As such, setting variable A to -1 then accessing array[A] will not return the last element.

Control flow

Workshop function OverPy representation
Skip(constant) goto label 1
Skip(variable) goto loc+variable
Skip If(constant, condition) if condition:
    goto label 1
Skip If(variable, condition) if condition:
    goto loc+variable
Abort return
Abort If(condition) if condition:
    return
Abort If Condition Is False if not RULE_CONDITION:
    return
Abort If Condition Is True if RULE_CONDITION:
    return
If(condition) if condition: 2
Else If(condition) elif condition: 2
Else else: 2
For Global Variable(variable, start, stop, step) for variable in range(start, stop, step):
For Player Variable(player, variable, start, stop, step) for player.variable in range(start, stop, step):
End unindent
Loop while true 3
or
continue 4
Loop If(condition) while condition 3
or
if condition:
    continue 4
Loop If Condition Is False while not RULE_CONDITION 3
or
if not RULE_CONDITION:
    continue 4
Loop If Condition Is True while RULE_CONDITION 3
or
if RULE_CONDITION:
    continue
While(condition) while condition: 2

1 label represents the label that the goto instruction will jump to. Labels are an alphanumeric word followed by a colon, such as lbl_0:. They can only be placed after the goto statement, in the same rule.
2 Currently, these instructions are decompiled using their internal functions such as __if__(). In the future, they will be decompiled using the proper structures.
3 The while instruction is only used if not within another block; in that case, a do: instruction must be added at the beginning of the rule, with the necessary indentation. Note that the while instruction has no colon at the end.
4 Currently, the continue instruction always goes to the beginning of a do/while loop. This is set to be changed in a future release, where the continue instruction will go to the beginning of the innermost do/while, while, or for loop.

Raycasts

Workshop function OverPy representation
Is In Line Of Sight(start, end, barrierLos) raycast(start, end, los=barrierLos).hasLoS()
Raycast Hit Normal(start, end, include, exclude, includePlayerObjects) raycast(start, end, include=include, exclude=exclude, includePlayersObjects=includePlayersObjects).getNormal()
Raycast Hit Player(start, end, include, exclude, includePlayerObjects) raycast(start, end, include=include, exclude=exclude, includePlayersObjects=includePlayersObjects).getPlayerHit()
Raycast Hit Position(start, end, include, exclude, includePlayerObjects) raycast(start, end, include=include, exclude=exclude, includePlayersObjects=includePlayersObjects).getHitPosition()

Chase

Workshop function OverPy representation
Chase Global Variable At Rate(variable, destination, rate, reevaluation)  chase(variable, destination, rate=rate, reevaluation)
Chase Global Variable Over Time(variable, destination, duration, reevaluation)  chase(variable, destination, duration=duration, reevaluation)
Chase Player Variable At Rate(player, variable, destination, rate, reevaluation)  chase(player.variable, destination, rate=rate, reevaluation)
Chase Player Variable Over Time(player, variable, destination, duration, reevaluation)  chase(player.variable, destination, duration=duration, reevaluation)
Stop Chasing Global Variable(variable) stopChasingVariable(variable)
Stop Chasing Player Variable(player, variable) stopChasingVariable(player.variable)

Rounding

Workshop function OverPy representation
Round To Integer(value, Up) ceil(value)
Round To Integer(value, Down) floor(value)
Round To Integer(value, To Nearest) round(value)

Vectors

Workshop function OverPy representation
X Component Of(vector) vector.x
Y Component Of(vector) vector.y
Z Component Of(vector) vector.z

Subroutines

Workshop function OverPy representation
Call Subroutine(subroutine) subroutine()
Start Rule(subroutine, behavior) async(subroutine, behavior)