Jump to content

Rommel

Member
  • Content Count

    1225
  • Joined

  • Last visited

  • Medals

Posts posted by Rommel


  1. The reason it doesn't work is because #define is a pre-processor command; ie before the game itself truly compiles the code.

    For example:

    #define MYVAR "test"
    
    if ("test" == MYVAR) exitwith {};
    

    The game engine during compilation see's this as:

    if ("test" == "test") exitwith {};

    Therefore, with your code:

    #define MYDEFINE "it works"
    
    call compile preprocessFileLineNumbers "fnc.sqf";
    
    sleep 3;
    call fnc1;

    Becomes:

    call compile preprocessFileLineNumbers "fnc.sqf";
    
    sleep 3;
    call fnc1;

    The code is then executed by the game engine, and becomes the following:

    call {fnc1 = {hint str(MYDEFINE)}};
    
    sleep 3;
    call {hint str(MYDEFINE)};

    The compiler has already made its pre-processor run through, long before this, so therefore MYDEFINE will not work.

    Try the following instead:

    init.sqf

    #define MYDEFINE "it works"
    
    MYDEFINE call compile preprocessFileLineNumbers "fnc.sqf";
    
    sleep 3;
    call fnc1;

    fnc.sqf

    fnc1 = compile format ["hint %1", _this];

    Therefore:

    call fnc1 == call {hint "it works"};


  2. _i = _a find 1;
    while {_i != -1} do {
    _a set [_i, "null"];
    _a = _a - ["null"];
    _i = _a find 1;
    };

    Really...

    @Dissaifer

    Minimal coding, if you use a something that has been processed twice, store it into memory.

    So instead of:

    _man = (units group _this) select 0;
    _man1 = (units group _this) select 1;

    Do:

    _units = units (group _this);
    _man1 = _units select 0;
    _man2 = _units select 1;

    Any constants should be defined and not stored into memory.

    So instead of:

    _distance = 30;
    _b = _distance * _this;
    _c = _distance / _this;

    Do:

    #define DISTANCE 30
    _b = DISTANCE * _this;
    _c = DISTANCE / _this;

    If you have a function, or a piece of code you execute multiple times, compile it and save it to a variable; saves constant compilation by the engine.

    So instead of:

    {
    if (alive _x) then {
    	_pos = getpos _x;
    	_pos set [2, 50];
    	_pos set [1, 20];
    	_pos set [0, (_pos select 0) - 2];
    	_x setpos _pos;
    };
    } foreach (units _group);

    Do:

    _fPos = {
    _pos = getpos _this;
    _pos set [2, 50];
    _pos set [1, 20];
    _pos set [0, (_pos select 0) - 2];
    _this setpos _pos;
    };
    {
    if (alive _x) then {_x call _fPos};
    } foreach (units _group);

    Obviously in that situation, it seems a bit stupid, but it can be very handy later and save on repeating lines of code over and over. Saves compilation too.


  3. What is RMM_recordPos

    A time saver. It records the players positions to an array, which can then (via trigger) be copied to your clipboard for easy output.

    Why would you use RMM_recordPos

    You can spend hours trying to get the perfect position for things in the editor, or even the 3D editor, but a hands on approach is still the best way when placing units in the 2D editor.

    How to use RMM_recordPos

    Use the action in the players menu 'record position', to add a position to the array, this is done via RMM_record.sqf.

    To copy the array to the clipboard, use 0-0-1

    To copy the current player position to the clipboard, use 0-0-2

    To reset the array, use 0-0-3.

    Hopefully this helps save time, I know it has for me.

    http://www.4shared.com/file/147105212/8a6023b3/RMM_RecordPosChernarus.html

    (fyi: attachments don't work; error received was 'cannot access uploads path')

×