Oxygen 2 Misc Documentation

From Bohemia Interactive Community
Jump to navigation Jump to search

This page is a list of found Oxygen 2 avilable commands and behaviours.


O2 Script

if then else

if (something == 1) then {fred=1;}else{fred=2;};

functions

_SomeFunc=
{
  
  private ["_in","_out"];
  _in=_this@0;
  if (_in== 1) then {_out=1;}else{_out=2;};
  out   // lack of semi colon returns content of out

equally

  if (_in== 1) then {1}else{2}; // achieves same
};

comment

comment "comment" /* comments

  • /

// comments

messageBox [text,nButtons]

Returns ID of pressed button

Shows message box with text and buttons.

nButtons is undocumented but probably follows the msoft conventions of ok, cancel, blah, + warning icons

nButtons 0: == OK only

isnil

example:

 if (isnil "_exists") ExitWith(_file_exists=false;};
 if (!isnil "_exists") ExitWith(_file_exists=true;};

note that exitwith is pretty close to useless it ONLY breaks out of the current braces, not, out of a subroutine per se


nil

example:

 _dirs= shellCmdOpenPipe("....
{
  process...
}
_dirs=nil;


File Commands

GetCD

See SetCD below.

SetCD

_folder=GetCD; // returns fully qualified (P:\etc)
_SetCD(folder);

openStandardIO

   Opens stream for standard input and output. If no standard I/O is assigned, creates console, and redirect I/O into console. Note: Always assign result to variable, and access stream with variable.

Example:

   console=openStandardIO; console<<"Hallo world"

console=nil; close it

openFile ["filename",mode]

  • Returns IOStream

Opens or creates a file specified by filename. Mode contain one of following values:

  • 0 - test existence of file (no open)
  • 1 - open existing file for reading
  • 2 - create new file for writting
  • 3 - open existing file for reading and writting
  • 4 - open (create if not exists) file for reading and writting

Example:

_file=openFile ["some\file\anywhere.ext",0];
if (!isnil("_file")) then {do_something;_file=nil;};

Note: _file will be non nil for mode 0

shellCmd "command"

Retursn: Result (number)

Function waits until command is finished

result is -1 if file not found, or cannot be started, otherwise returns application's exit code

Example:

   _result = shellCmd ("notepad.exe");

shellCmdOpenPipe "command"

Returns IOStream

Creates bi-directional pipe to the new process. Script can use this pipe to send commands to child process and read its results

Example:

_files=shellCmdOpenPipe ("dir /b/a:-d-h/L *.p3d"); list only p3d files in lower case, no hidden stuff
while "!eof _files" do 
{
 _filename= getline _files;
 if (_filename!="") then {[_filename] call something;};
};
_files=nil;

SplitPath "Path"

Returns the Path string into a 4 element array

   [drive,folders,filename,extension]


Example:

   splitPath "C:\test\anywhere\anyFile.txt" , result is ["c:","\test\anywhere","anyFile",".txt"]

this command does not work as nature intended

the drive is force-set to current drive

the folder path is determined by current directory

a lack of preceding slash adds it. any drive specification in the string (such as proxy:) is treated as folder path (part of)