Jump to content
Sign in to follow this  
maruk

Arma 2 Forward Compatibility

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:

_number = 0;
if (number == 0) then {hint "Zero"};

DIDN'T WORK:

Becouse the variable has to be initialized BEVORE then {};

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.

Edited by W0lle

Share this post


Link to post
Share on other sites
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.

Edited by W0lle

Share this post


Link to post
Share on other sites

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

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

Bad

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

Edited by W0lle

Share this post


Link to post
Share on other sites
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.

Edited by W0lle

Share this post


Link to post
Share on other sites

if (alive player) then {_number = 0};
if (_number == 0) then {hint "Zero"};  //ERROR IN ARMA1 ALSO

IN ARMA2: single I want to know if the functions return null values

thanks

Edited by W0lle

Share this post


Link to post
Share on other sites

It would have been nice to see ArmA 1 with a command line parameter for developers to turn on this new "nil variable checking" already.

It would allow ArmA 1 scripts to be properly tested for easier porting to ArmA 2, in anticipation of it's release.

- It would already be very useful for debugging now.

- It seems like a fairly simple change to implement.

- By making it a exe param, it wouldn't interfere with existing mission scripts.

Share this post


Link to post
Share on other sites

I'm pretty sure that everything from Arma will work in Arma2 so it shouldn't be the problem that we have now with OFP to Arma.

There are many of us here creating Arma mods that can be ready on Day 1 of Arma2, if all goes according to plans.

--Ben

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (alive player) then {_number = 0};

if (_number == 0) then {hint "Zero"}; //ERROR IN ARMA1 ALSO

IN ARMA2: single I want to know if the functions return null values

thanks

Yes becouse the variable was not initialized bevore the then {_number = 0};

Here is whats written in the biki about it:

Quote[/b] ]

If a local variable is initialized within a Control Structures (i.e. if, for, switch, while) its scope will stay within this structure (i.e. outside of the structure it will still be seen as undefined).

This does not apply to global or public variables.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (alive player) then {_living=true}; hint format["%1",_living];

Returns "scalar bool array string 0xe0ffffef", since the local variable was not initialized before being used within a control structure.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_dead=true; if (alive player) then {_dead=false}; hint format["%1",_dead];

Returns "false", since the variable was initialized before the if...then.

EDIT: 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.

So this will reported as an error!

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (alive player) then {_number = 0};

if (_number == 0) then {hint "Zero"};   //ERROR IN ARMA1 ALSO

IN ARMA2:  single I want to know if the functions return null values

thanks

The logic of that code is wrong and there is no reason to change it to be right in ArmA 2. It is right that it doesn't work.

Familiarize yourself with the programming concept "scope".

Share this post


Link to post
Share on other sites
EDIT: 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.

So this will reported as an error!

In ARMA1 also is ERROR.

Share this post


Link to post
Share on other sites
Guest

Just to get a clear answer, due to the fact ive heard various rumors that Arma2 will not support it..

Will Arma2 support .Sqs block form code? Or only .sqf?

Share this post


Link to post
Share on other sites
Guest
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (alive player) then {_number = 0};

if (_number == 0) then {hint "Zero"}; //ERROR IN ARMA1 ALSO

IN ARMA2: single I want to know if the functions return null values

thanks

The logic of that code is wrong and there is no reason to change it to be right in ArmA 2. It is right that it doesn't work.

Familiarize yourself with the programming concept "scope".

it can work

maybe it depends on usage :

_ArtyGroup is undefined before these lines

;get proper arty crews from the clan number

;this is for getting correct crew names to join garrison units to for manning taken over arty pieces

?(_ClanNumber == 1):_ArtyGroup = VallonArtyCrew

?(_ClanNumber == 2):_ArtyGroup = ErudinArtyCrew

?(_ClanNumber == 5):_ArtyGroup = PovarArtyCrew

?(_ClanNumber == 7):_ArtyGroup = KaranaArtyCrew

?(_ClanNumber == 10):_ArtyGroup = RallosArtyCrew

?(_ClanNumber == 12):_ArtyGroup = TunareArtyCrew

;now leaving Rohan arty as a possibility, for Rohan taking over a town, this arty group is initiated at mission start as well

?(_ClanNumber == 14):_ArtyGroup = RohanArtyCrew

?(_ClanNumber == 3):_ArtyGroup = OgokkArtyCrew

?(_ClanNumber == 4):_ArtyGroup = MorkanArtyCrew

?(_ClanNumber == 6):_ArtyGroup = RatheArtyCrew

?(_ClanNumber == 8):_ArtyGroup = MarrArtyCrew

?(_ClanNumber == 9):_ArtyGroup = FelwitheArtyCrew

?(_ClanNumber == 11):_ArtyGroup = DruzzleArtyCrew

?(_ClanNumber == 13):_ArtyGroup = ThuragArtyCrew

works fine, no errors

When _ArtyGroup is checked, it always returns the proper global, no errors

Now in a case where one of these lines did not execute to initialize _ArtyGroup, of course it would then fail.

My understanding, is, either way, in this case, Arma2 will not support this, in my case, _ArtyGroup would have to be initialized before hand, and equal "something" before it could be used in the "then" part of an "if Then" statement.

That kinda suks lol, because many of my scripts initialize locals thru if/then statements, and initializing them before hand will certainly add quite a bit of length to the initial parts of the scripts, but o well- it can be done smile_o.gif

Share this post


Link to post
Share on other sites

That is very nice. My all scripts in ArmA are still SQS because its simple, stable and I havent found any restrictions from it yet.

Share this post


Link to post
Share on other sites
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.

Any ideas what this means exactly. Will we still be able to interact with our own dialogs and scripts/objects running in game, in real time?

Share this post


Link to post
Share on other sites
Any ideas what this means exactly. Will we still be able to interact with our own dialogs and scripts/objects running in game, in real time?

As far I understand it, short answer "yes".

Considering your scripting work so far I assume you are familiar with the general concept of namespaces in programming.

Now it seems that you will no longer be able to directly manipulate global variables in your UI scripts from mission (/addon?) scripts and vice versa. I suspect you would have to do something like let's say invoke a UI function with parameters you would like to have manipulated, this UI script would then be able to manipulate UI global variables.

For example:

Let SCH_GLOBAL_STRING be a global variable in UI namespace.

Now invoking the follwing command from mission namespace would not work

SCH_GLOBAL_STRING = "Some text"

Now let "setText.sqf" be the following UI script:

SCH_GLOBAL_STRING = _this

You could then manipulate UI namespace variable with

"Some text" call compile loadFile "setText.sqf"

I could be completly wrong here, of course :cool:

If I am not, I hope there will be a more elegant way to do this (if not, you will probably be able to work one out yourself)

Share this post


Link to post
Share on other sites

Any official word on what this namespaces will actually entail; any chance BIS could ease our minds and give us a small example? Come on Ondrej! :P

Share this post


Link to post
Share on other sites

I'm guessing the UI namespace relates to the UI event handlers mainly, which are strings. (eg: MouseButtonDown, LBListSelChanged, Action, etc).

But I'm guessing if you execute a script from those EH's, then those scripts will still have access to global variables, so long as they are not passed in as parameters, so you would simply need to move your processing logic into there.

This would then encourage you to use the control which is already passed via the parameters too.

Maybe they are expanding the ability to use nested dialogs or are providing access to certain Arma dialog's (eg: main menu(/action menu), scoreboard, etc)

Share this post


Link to post
Share on other sites
I'm guessing the UI namespace relates to the UI event handlers mainly, which are strings. (eg: MouseButtonDown, LBListSelChanged, Action, etc).

In retrospect, I figure there must be some interaction allowed. Otherwise there is no point in having dialogs, if you can't do anything with them.

Share this post


Link to post
Share on other sites

Please dont spam our forums here, if you have nothing to contribute or any problem,

or idea that you need help on then dont say anything at all.

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
Sign in to follow this  

×