if – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
m (? is not alternative syntax)
No edit summary
Line 48: Line 48:


? is not an alternative syntax for if. ? is a special construct available in [[SQS syntax]] only, similar to other SQS specific constructs. --[[User:Suma|Suma]] 22:49, 29 September 2007 (CEST)
? is not an alternative syntax for if. ? is a special construct available in [[SQS syntax]] only, similar to other SQS specific constructs. --[[User:Suma|Suma]] 22:49, 29 September 2007 (CEST)
== Complete Evaluation ==
if (count _array > 0 and _array select 0 == "foo") then {}
[[if]] statements are "complete evaluation" rather than "short circuit". In other words everything is evaluated. So the above example would error if _array had no elements because the second part will fail. (Thanks to HitmanFF for pointing out term for this type of evaluation.) --[[User:Doolittle|Doolittle]] 21:19, 28 January 2008 (CET)

Revision as of 22:19, 28 January 2008

Return value

Will or can the return value of the if statements be changed in such a way, that the normal braces aren't needed anymore to catch the result?

hint if(_var==1) then {"equals 1"} else {"doesn't equal 1"}

doesn't work right now, since OFP returns an error, that you can't pass if types to the hint command. This is not much of a problem, since you can simply put braces arount the if statement.

Where removing this error would be really helpful though, are "else if" statements. Caused by the above circumstances, "else if" statements have to be written like this in OFP:

if (_var==1) then
{
    hint "condition 1";
}
else (if (_var==2 && _var2==1) then
{
    hint "condition 2";
}
else (if (_var5 > 0) then
{
    hint "condition 3";
}
else
{
    hint "no condition filled";
}));

This would look much more beautiful and would be much easier to script, if we could get rid of those braces around if statements, which could be fixed easily (or not) by changing the circumstance pointed out above. --hardrock 13:48, 24 July 2006 (CEST)

And what about switch?
switch (_var) do {
    case 1: {
        hint "condition 1";
    }; case 2: {
        hint "condition 2";
    }; default {
        hint "condition 3";
    };
}
I'm not sure about semicolons, but idea should be correct. --Djura 19:29, 24 July 2006 (CEST)
Sorry, I passed over you have three diferent _var variables. --Djura 19:29, 24 July 2006 (CEST)
Exactly. We can do fine checking one variable with switch, but as soon as we have different conditions, "else if" is needed (or "elseif", as it's sometimes written) --hardrock 14:48, 25 July 2006 (CEST)

? is not alternative syntax

? is not an alternative syntax for if. ? is a special construct available in SQS syntax only, similar to other SQS specific constructs. --Suma 22:49, 29 September 2007 (CEST)

Complete Evaluation

if (count _array > 0 and _array select 0 == "foo") then {}

if statements are "complete evaluation" rather than "short circuit". In other words everything is evaluated. So the above example would error if _array had no elements because the second part will fail. (Thanks to HitmanFF for pointing out term for this type of evaluation.) --Doolittle 21:19, 28 January 2008 (CET)