Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 48

  Click here to go to the first Developer post in this thread.  

Thread: Arma 2 Forward Compatibility

  1. #21
    Although this is perfectly valid in arma:
    Code Sample

    MyGlobalVariable = nil;
    I don't think that is a declaration - very much the reverse! Note the following is not based on any knowledge of ArmA internals but from experience with analoguous interpreted systems. It's possible BIS have a different implementation but I would be surprised if so...

    The best way to think of 'definedness' of variables is to consider that they live in a database(1) where entries consist of name/value pairs.

    When you create a new variable with "myVar=1" you are actually creating an entry in the database where the 'name' field is set to "myVar" and the 'value' field is set to 1. (There is probably a 'type' field in ArmA but this is irrelevant to this discussion.)

    When you subsequently run "myVar=2", the existing entry is updated with a new value field.

    Assigning a 'value' of 'nil' to a variable can be used to remove an entry from the database. Note that 'nil' is not really a value at all, it is simply a convenient syntax. So you should really think of "myVar=nil" as "Undefine myVar". Similarly the 'isNil' command is best thought of as a test to see if an entry for that variable exists in the database.

    Another point, in contrast to 'nil', which means that a variable doesn't even exist, 'null' is a valid value and just means that the thing to which the variable refers doesn't exist.

    So, I would expect the following behaviour...
    Code:
    //Define a variable
    myVar=1;
    //Now delete it again
    myVar=nil;
    
    //Testing for existence can be done with 'isnil'
    if (isNil "myVar") then {
      hint "no variable called myVar exists";}
    
    //This should throw an error in Arma2 since we've just
    //deleted the variable
    hint format ["myvar is %1",myVar];
    The 'private' command is interesting since it implies that it is creating uninitialised variables. When I get some time on my gaming PC I'll have a quick check to see if those variables are created with a null value.

    (1) Of course, 'database' is a loose term here - it is usually a table/linked-list/hash/binary-tree or other simple structure.
    Last edited by W0lle; Apr 13 2009 at 04:58.
    Author of PVPmissionWizard ArmA2FPSAnalyser AddonChecker and ... squint

    Tools homepage

    Crosseyed and Painless - a blog about my ArmA2 developments



  2. #22
    There was some suggestion somewhere that SQF format scripting is the way forward.
    Will ArmA 2 support SQS and SQF, or SQF only?

  3. #23
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    I belive ArmA 2 will support like ArmA 1 bouth .sqs and .sqf there is no reason why BIS should drop .sqs

  4. #24
    Hi

    Code:
    _func = 
    {
       _return = nil;
       _return
    };
    
    _var = [] call _func;
    
    if !(isNil "_var") then
    {
     ...................
    };

    this gives error?
    Last edited by W0lle; Apr 13 2009 at 04:59.

  5. #25
    Sqf is imho indeed the way forward.
    It's structure is imho a lot better compared to sqs and the possibilities to precompile and call or spawn later is a huge plus also.
    I also believe in unification and generalization of code, so imho all should be coded in 1 language and not multiple. As SQF has it's advantages over SQS I drop SQS as a whole personally.

    I believe sqs will still be supported in ArmA2, but why would you use it is my question
    A.C.E. Advanced Combat Environment

    Dev-Heaven.net Free Project Hosting | A2 Community Issue Tracker Help BIS, Help yourself!

  6. #26
    SQS makes for ugly, hard to follow, compromised code. SQF is also easier to use and more closely resembles what you may be used to if you used other languages. To me, it feels as if my Arma projects run smoother that my OFP ones.
    --Ben

  7. #27
    Sergeant Major SNKMAN's Avatar
    Join Date
    Aug 29 2006
    Location
    Germany ( Lake Constance )
    Posts
    1,616
    Quote Originally Posted by (rrores @ Dec. 18 2007,11:19)
    Hi

    _func =
    {
    _return = nil;
    _return
    };

    _var = [] call _func;

    if !(isNil "_var") then
    {
    ...................
    };


    this gives error?
    Well i understood it this way:

    You have to initialize every variable bevore first use so:

    WORKS:
    Code:
    _number = 0;
    if (number == 0) then {hint "Zero"};
    DIDN'T WORK:
    Becouse the variable has to be initialized BEVORE then {};

    Code:
    if (alive player) then {_number = 0};
    if (number == 0) then {hint "Zero"};
    But you still can use "isNil" becouse isNil do only check if the variable exist, and if not then it will be created.
    Last edited by W0lle; Apr 13 2009 at 05:01.

  8. #28
    Quote Originally Posted by (SNKMAN @ Jan. 23 2008,16:32)
    DIDN'T WORK:
    Becouse the variable has to be initialized BEVORE then {};

    if (alive player) then {_number = 0};
    if (number == 0) then {hint "Zero"};
    (thanks to respond)

    that does not work either in arma1.
    Last edited by W0lle; Apr 13 2009 at 05:02.

  9. #29
    Basicly it just comes down to this:
    You must first initialize (set variable Type) a variable before you use it:


    Good:
    _var1 = 0; player globalChat format ["Test: %1", _var1];

    Bad:
    player globalChat format ["Test: %1", _var1];

    This code in ArmA would make player globalChat sth like "Test: SCALAR BOOL ARRAY STRING ....."
    The same code in ArmA2 will report an error, because _var1 was not initialized before.

    Good
    Code:
    if (isNil "GlobalVar") then { GlobalVar = "" };
    player globalChat format ["%1", GlobalVar];

    Bad

    Code:
    player globalChat format ["%1", GlobalVar];
    This code in ArmA would make player globalChat sth like "SCALAR BOOL ARRAY STRING ....."
    The same code in ArmA2 will report an error, because GlobalVar was not initialized before

    Hi

    _func =
    {
    _return = nil;
    _return
    };

    _var = [] call _func;

    if !(isNil "_var") then
    {
    ...................
    };


    this gives error?
    I think this will work just fine. _var = nil destroys a variable if it existed, but doesnt create it if it didn't before.
    isNil "_var" should be a valid test
    Last edited by W0lle; Apr 13 2009 at 05:05.

  10. #30
    Master Gunnery Sergeant
    Join Date
    Sep 10 2004
    Location
    Finland
    Posts
    1,287
    Quote Originally Posted by (rrores @ Jan. 24 2008,07:53)
    Quote Originally Posted by (SNKMAN @ Jan. 23 2008,16:32)
    DIDN'T WORK:
    Becouse the variable has to be initialized BEVORE then {};

    if (alive player) then {_number = 0};
    if (number == 0) then {hint "Zero"};
    (thanks to respond)

    that does not work either in arma1.
    There is a typo isn't there.

    And it is intentionally done wrong (not the typo but the logic) to show you what doesn't work.
    Last edited by W0lle; Apr 13 2009 at 05:02.

Page 3 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •