Jump to content
engima

[RELEASE] SQX Language - Object Oriented Scripting

Recommended Posts

WHAT IS SQX?

SQX is a script language that is used to create scripts and missions in Arma 3. SQX is very similar to SQF, but it has support for object oriented scripting.

 

PHILOSOPHY

SQX extends the SQF language primarily by adding control structures that allow for object oriented scripting. As such, plain SQF is allowed, but it also introduces support to organize the code into classes and inheritance. SQX also introduces a small toolbox of some optionally available new commands and keywords that may be helpful (such as the "return" statement). The SQX language reference explains all the ways that SQX differs from SQF. One could say that SQX is for SQF what TypeScript is for Javascript.

 

FEATURES OF SQX

  • True object orientation (objects and inheritence, virtuals and overrides)
  • Type handling and customizable types (classes, interfaces, enums)
  • Three different kinds of class members (fields, methods, properties)
  • Three different kinds of accessors (private, protected, public)
  • Support for statics (methods and properties)
  • Syntax close to SQF
  • Some new convenient commands (like "is", "as", "return" etc.)
  • Compiler synchronizes line numbers between SQX and SQF to support runtime error handling
  • Objects can be broadcasted between machines
  • Complete reference documentation (at www.typesqf.com).


WHAT CAN YOU DO?
You can structure your code in an object oriented way, creating your own types and actions using classes, interfaces and enums. Well, these are just the tools. What you really can achieve is great structured code, easy to read, easy to write and easy to understand. It extends the boundaries of what code is possible to overview and control.

 

WHAT IS OBJECT ORIENTATION?

Start with this Wikipedia article: https://en.wikipedia.org/wiki/Object-oriented_programming.

 

HOW TO GET STARTED?

  1. Download the TypeSqf Editor from www.typesqf.com.
  2. Create a new mission.
    • In Eden Editor in Arma 3, create a new mission and insert at least one playable unit.
    • In TypeSqf, select "Open mission" and select the newly created mission.sqm.
  3. Install the CPack TypeSqf.MissionTemplate.Mp.Standard.
    • In TypeSqf, open the CPack Console in the Tools menu.
    • Write "Install TypeSqf.MissionTemplate.Mp.Standard" and press ENTER. The mission template (written in SQX) is now installed into your mission.
  4. Compile and build the project and play the default template mission.
    • Compile the mission in TypeSqf by using "Compile project" on the Build menu.
    • Play the simple default mission.

 

MEDIA

The following video shows when I use SQX to create and use a Crowd object:

 

 

HOW DOES IT WORK?
A class instance variable (instantiated with the new keyword) is under the hood an SQF variable of type Array. The class instance's fields and properties are saved as array items in an order kept track of by the SQX compiler. Methods compiles into global functions, with the instance variable (the class array) sent in as the first parameter. This is of course all abstracted by the compiler and not visible to the developer. All SQX is written into .sqx files, and all .sqx files are then compiled into .sqx.sqf counterparts enabling them to be read and interpreted by Arma 3.

 

SOME IMPORTANT NOTES
A language limitation: Due to limitations in SQF arrays it is not possible to instantiate two classes that reference each other. I.e. a parent class can have children, but these children cannot contain references back to its parent. The solution is simply to avoid these kinds of structures, and if you do it you will get a runtime error.

 

An editor limitation: The TypeSqf editor does not have complete autocompletion regarding SQX, but it helps with the most common stuff. E.g. it only suggests one level of chained properties and methods, and it suggests variable names by searching the whole file instead of the actual programming scope context. If you are an advanced developer, please remember that the SQX language does handle most of expected code structures, which is more than the editor will suggest.

 

THE TYPESQF EDITOR

Note that this forum is for the SQX Language, which is closely related to, but also separated from, the TypeSqf Editor. Please only post questions and comments regarding the SQX Language here. Questions and comments about the TypeSqf editor goes into the TypeSqf forum.

 

VERSION HISTORY

Version 1.01

  • SQX: Added checks for when a sub class is missing call to explicit base constructor.

 

Version 1.0

  • First version.
  • Like 6
  • Thanks 1

Share this post


Link to post
Share on other sites

I start out with a comment myself.

 

The TypeSqf editor and the SQX script language is something I just made for fun. It is not perfect (there will always be sharp edges to polish), but it is very good. At least regarding my own needs.

 

I’ve been working with them in parallell for quite some years. SQX has been a bit hidden in the back of the TypeSqf editor until now. But I think it has proven itself enough, so why not release it at last.

 

Well, if it is useful for someone else too, it would be awesome!

 

Happy coding!

  • Like 3

Share this post


Link to post
Share on other sites

New version: 1.01

  • SQX: Added checks for when a sub class is missing call to explicit base constructor.
  • Like 2

Share this post


Link to post
Share on other sites

Hi Engima, congratulations on creation of this SQF extension, I really like it, I hope that more people will turn to OOP SQF!

Me and my friends have been using our custom preprocessor-based implementation of SQF OOP, you can check example files made with it if you want: https://github.com/Sparker95/Vindicta/blob/GOAP-AI/Vindicta.Altis/OOP_Light/OOP_Light.h

Regarding the problem with parent-child references: arma doesn't allow recursive arrays, one possible solution would be like this: when we create an object, instead of making an array and returning this array to user directly, you could store the array in some unique variable in missionNamespace, and return that string. But it would mean that in your OOP created objects will not be auto-deleted when they go out of scope, like objects returned by classic C++ new operator.
Or maybe another solution, you could keep the current implementation of objects as structs which are passed by value and their life time is auto-manage and the one I proposed above as actual objects allocated in the heap? Overall, not being able to have a back-reference in an OOP language feels quite limiting.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×