User Tools

Site Tools


arma2:scripting

This is an old revision of the document!


Scripting

ArmA 2 will be largely compatible with Armed Assault. To make porting of content from ArmA as simple as possible, there are few important things:

  • using of undefined variable in scripts (nil value) will be in ArmA 2 strictly reported as an error. All variables used in any scripts must be initialized before first use.
  • in ArmA 2 namespaces will be introduced for user scripts and variables. There are many low level reasons to do this and most of the content will be not be affected by this in any negative way. However, in order to be prepared, it is very important to separate UI related scripts and code as much as possible and not simply share global variables between UI and missions as UI namespace needs to be handled differently.
  • in order to maintain smooth frame rate in real-time content, time limit for all scripts in each frame is enforced by the engine in ArmA 2. Generally speaking, in case of more demanding scripts, be prepared that their result may come way later and also there probably can suffer from significant latency. It is under evaluation if and how possibly allow user scripts to change how much time they may take from the CPU in every frame.
  • SQS script format will be fully supported in ArmA 2.

initJIPcompatible.sqf is automatically started at unknown time, best guess would be when JIP player joins?

Multiplayer Dedicated server broadcasting to all clients.

Some Code optimization tips.

Scripting Commands

There's a lot of cool scripts (functions) available in Modules.pbo - especially under “Functions” and even an multiplayer Framework in “MP”.

Since ArmA 2 you must first initialize a variable before you reference it in your scripts. In ArmA, it was not a problem, at least for conditions.

// this will error if myBoolean was not previously defined.
if (myBoolean) then { hint "test" };

Usage of isNil is still valid.

Few more Scripting command reference items.

taskHint.sqf

How to make task hints

taskHint is relatively useless itself (because it requires too much effort), but there is a script that makes it easier to use. So instead of executing a hint, do this:

[objNull, objNull, tskExample1, "SUCCEEDED"] execVM "CA\Modules\MP\data\scriptCommands\taskHint.sqf";

The first 2 arguments are useless so i just send objNull, the 3rd is the task that you've created, and the 4th is the status.

Supported task states: “CREATED”, “CURRENT”, “CANCELED”, “SUCCEEDED” and “FAILED”.

  • This command does not set the state of the task, so you still need to do this command, and the setTaskState command in your trigger.
  • It creates the hint in the middle of the screen, not at the right side (this means that taskHint and hint can be used at the same time).
arma2/scripting.1310483518.txt.gz · Last modified: 2011-07-12 15:11 by snakeman