Jump to content
Sign in to follow this  
gnurf

If true type {}

Recommended Posts

I just spent a couple of hours rewriting a fully functioning script that i´ve been developing for the past few weeks. The reason i rewrote it was becouse alot of times there would be two if operators testing the same value and setting a variabel each

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

? _metrue : _variabel1 = 1

? _metrue : _variabel2 = 2

<span id='postcolor'>

So I figured i that i could simplifie this by having only one if operator and using then {} to execute the setting of the two variabels

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

? _metrue then

{

_variabel1 = 1

_variabel2 = 2

}

<span id='postcolor'>

Imagine the joy I felt when I discoverd that I apparently aint allowed to do that biggrin.gif

if operator (and all other logical operators, i assume) must have their function body on the same row as the operator it self

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

? _metrue then {_variabel1 = 1}

<span id='postcolor'>

Ok I can live with that and have the whole body of the operator on one row (they will be long and hard to debug but what you gonna do biggrin.gif ). BUT PLEASE!!!! let there be away to add more then one event to the operators body

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

? _metrue then {_variabel1 = 1 _variabel2 = 2}

<span id='postcolor'>

I could still use the old version of the script...but i dont want to.

Share this post


Link to post
Share on other sites

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

? _metrue: _variable1 = 1; _variable2 = 2; _variable3 = 3; ...

<span id='postcolor'>

wink.gif

Share this post


Link to post
Share on other sites
Guest

You are mixing scripting commands with function call commands. In OFP functions (called with the call command) are basically strings.

So, if you want to mix 'em you have to be sure to do it correctly smile.gif

Something like this:

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

?_a>_b: call "C=0;D=1" or ?_a>_b: call {C=0;D=1}

<span id='postcolor'>

Note that by using that you can only write to global variables since local variables defined within the scope of "" or {} won't exist after the call command is completed!

Now if you keep to only function syntax then you write it liike this:

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

if(_a>_b) then

{

_C = 0;

_D = 1;

};

<span id='postcolor'>

or shorter

if(_a>_b) then "_C = 0;_D = 1";

If you want to use script syntax only, do as bigboppa wrote smile.gif

Share this post


Link to post
Share on other sites

Thanks both of you smile.gif

bigpoppa´s tip works excellent (just tested it on a small test script)

denoir, im sure all you wrote is true but, i cant say i understood half of it. (probably becouse im an idiot tounge.gif )

I anticipated that the varaibels in {} would be locals so thats no problem. But whats the diffrence between scripting commands and function call commands? Can both types be used in a script *.sqs? Im asking becouse when i run this code

i get an "invalid number in expression" error.

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

if(_a>_b) then

{

_C = 0;

_D = 1;

};

<span id='postcolor'>

Maybe its a bit to much to ask for an explenation to all this, so if anyone could help point me in the right direction to some information it would be really apreciated.

Thanks again! smile.gif

Share this post


Link to post
Share on other sites
Guest

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Gnurf @ Dec. 31 2002,02:40)</td></tr><tr><td id="QUOTE">I anticipated that the varaibels in {} would be locals so thats no problem. But whats the diffrence between scripting commands and function call commands? Can both types be used in a script *.sqs?<span id='postcolor'>

Nope they can't. Functions are defined in sqf fíles. A function is actually treated as a single expressions so there a number of limitations. Script constructs @,~, ? or goto are not allowed. Semicolons are strictly required, as end of line has no special meaning and is considered as normal space character.

Example: If a < b then loop 10 times writing "Hello" to screen. a,b are input parameters.

Script: loop.sqs

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

_a = _this select 0

_b = _this select 1

_i = 0

?_a>b:goto "end"

#loop

hint "Hello"

_i = _i + 1

?_i<11: goto "loop"

#end

<span id='postcolor'>

Function:

loop.sqf

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

private ["_a", "_b", "_i"];

_a = _this select 0;

_b = _this select 1;

_i = 0;

if(_a<_b) then

{

  while "_i < 10" do

  {

    hint "hello";

    _i = _i+1;

  };

};

<span id='postcolor'>

They are also called differently:

Script:

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

[a,b] exec "loop.sqs"

<span id='postcolor'>

Function:

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

[a,b] call loadFile "loop.sqf"

<span id='postcolor'>

The big advantage of functions is that they can return values:

sum.sqf:

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

private ["_a", "_b", "_c"];

_a = _this select 0;

_b = _this select 1;

_c = _a + _b;

_c

<span id='postcolor'>

Gives the possibility of

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

_c = [_a,_b] call loadFile "sum.sqf"

<span id='postcolor'>

Which is impossible with scripts.

Share this post


Link to post
Share on other sites

They can return values!?!

the possibilites! wow.gif

Thanks for all the help and information

Cant thank you enough smile.gif

Share this post


Link to post
Share on other sites

Is this code working?

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">if {player1 hasweapon Binocular} then {player1 showmap true}<span id='postcolor'>

and I want to force all other players showmap false...

how does it working?

thanks

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  

×