Enforce Script Syntax – DayZ

From Bohemia Interactive Community
Jump to navigation Jump to search
(→‎Assignments: Define -> Assign)
(Change syntaxhighlighting lang to Java.)
Line 62: Line 62:
=== Basic Class Example ===
=== Basic Class Example ===


<syntaxhighlight lang=cpp>
<syntaxhighlight lang=java>
class MyClass  
class MyClass  
{
{
Line 94: Line 94:


=== Basic Script Example ===
=== Basic Script Example ===
<syntaxhighlight lang=cpp>
<syntaxhighlight lang=java>
MyClass myClass = new MyClass();
MyClass myClass = new MyClass();
myClass.myMethod();
myClass.myMethod();
Line 104: Line 104:
In order to get your custom code to work and function on top of another class already in the game, a modded class is where you want to turn to.
In order to get your custom code to work and function on top of another class already in the game, a modded class is where you want to turn to.


<syntaxhighlight lang=cpp>
<syntaxhighlight lang=java>
modded class PlayerBase  
modded class PlayerBase  
{  
{  

Revision as of 11:20, 20 December 2018

Enforce Script is the language that is used by the Enfusion engine first introduced in DayZ Standalone. It is a Object-Oriented Scripting Language (OOP) that works with objects and classes.

Operators

Arithmetic Operators

Operation Symbol
Add +
Subtract -
Multiply *
Divide /

Assignments

Operation Symbol
Assign value to variable =
Increment variable by value +=
Decrement variable by value -=
Multiply variable by value *=
Divide variable by value /=
Increment variable by 1 ++
Decrement variable by 1 --

Comparison

Operation Symbol
More than value >
Less than value <
More or equal to the value >=
Less or equal to the value <=

Classes and Objects

Classes can be seen as a blueprint of an object. An object is an instance of a class. A class can have more than one object.

Basic Class Example

class MyClass 
{
	private string _test;

	void MyClass() 
	{
		// Constructor that will be called when class gets instantiated
	}

	void myMethod()
	{
		// Some code here
	}
	
	string getTest() 
	{
		return _test;
	}

	string setTest(value) 
	{
		_test = value;
	}
}

Instantiate and Use

Write new YourClassName() to instantiate - create a new instance of a class, and assign it to some variable which type is YourClassName. After assign the instance, you can access attributes and methods inside a class through that variable by using dot notation like myClass.myMethod().

Basic Script Example

MyClass myClass = new MyClass();
myClass.myMethod();
myClass.setTest("Hello, Enforce Script!");
string str = myClass.getTest(); // str is now "Hello, Enforce Script!"

Modded class

In order to get your custom code to work and function on top of another class already in the game, a modded class is where you want to turn to.

modded class PlayerBase 
{ 
	override void EEKilled(Object killer) 
	{
		// This will call the method in which you are overriding.
		// Do this if you want to keep the original functionality
		super().EEKilled;

		// Custom code here (i.e. Print(killer.GetIdentity().GetName()))
	}
}