if – Talk

From Bohemia Interactive Community
Revision as of 18:25, 24 July 2006 by Djura (talk | contribs) (Another solution)
Jump to navigation Jump to search

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.