Jump to content
Sign in to follow this  
ravsun

If then else stament

Recommended Posts

Why doesn't this work?

if (triggerActivated test1 and triggerActivated test2) then

{

hint "Command Support Available";

}

else

{

hint "Support not Available. Try Completing a mission first.";

};

Or just this?

if (triggeractivated test1) then {

hint "Command Support Available";

} else { hint "Support Unavailable. Try completing a Mission first.";} ;

Or just this?

_t1 = (triggeractivated test1)

_t1 = false

if (_t1) then {

hint "Command Support Available";

}

Any help would be great.

Thanks

Edited by ravsun
Notification

Share this post


Link to post
Share on other sites

Still can't get if then statements working.

Share this post


Link to post
Share on other sites

For debugging purposes just do the following and see what it says:

systemChat format ["Trigger 1 activation is: ",triggerActivated test1]; systemChat format ["Trigger 2 activation is: ",triggerActivated test2];

Edited by JShock

Share this post


Link to post
Share on other sites

it just doesn't work it will not display a hint it will not activate. at work right now and I can't test debug. is the syntax I used correct?

Share this post


Link to post
Share on other sites
is the syntax I used correct?

The first bit should work, so that is why you need to debug the returns of each triggerActivated. I would also recommend turning on -showScriptErrors in your startup parameters if you haven't already.

Share this post


Link to post
Share on other sites

Incorrect information posted previously.

I'm not sure why your first example isn't working. It looks OK to me. :confused:

Edited by ST_Dux

Share this post


Link to post
Share on other sites

Can you post the full script and also the script that calls it? Those 3 if statements are syntactically correct. The only problem that I saw was that the last if statement will never, ever (in millions of years) be run because you set the condition to false right before it.

Share this post


Link to post
Share on other sites

When you post code, type [.code] before the code and [./code] at the end, WITHOUT the periods in them.

Makes it look cleaner :)

Share this post


Link to post
Share on other sites

if (triggerActivated test1 and triggerActivated test2) then
{
hint "Command Support Available";
}
else
{
hint "Support not Available. Try Completing a mission first.";
}; 

This snippet it completely correct, how and where do you call it ? I guess there lies the error.

Share this post


Link to post
Share on other sites

Definitely need to know how and when you are running this statement... Try replacing it with this:

systemChat format ["Test 1 Status: %1", triggerActivated test1];
systemChat format ["Test 2 Status: %1", triggerActivated test2];

if ((triggerActivated test1) && (triggerActivated test2)) then
{
hint "Command Support Available";
} else {
hint "Support not Available. Try Completing a mission first.";
};

Share this post


Link to post
Share on other sites

Perhaps check the triggers themselves. Are you using the right params, e.g. Activated by Blufor, Condition: this, etc.

Share this post


Link to post
Share on other sites

This works:

systemChat format ["Test 1 Status: %1", triggerActivated test1];

systemChat format ["Test 2 Status: %1", triggerActivated test2];

if ((triggerActivated test1) && (triggerActivated test2)) then

{

hint "Command Support Available";

} else {

hint "Support not Available. Try Completing a mission first.";

};

but this wiill not work if i have "s1 in thisList" in condition.

Edited by ravsun

Share this post


Link to post
Share on other sites
null = [] execVM "support\hint.sqf";

On activation of a trigger.

---------- Post added at 23:49 ---------- Previous post was at 23:31 ----------

null = [] execVM "support\hint.sqf";

On activation of a trigger.

If you would like to activate it at the start of a mission, create an init.sqf and place that code into their but remove the "null = " bit. :)

Share this post


Link to post
Share on other sites

null = [] execVM "support\hint.sqf";

On activation of a trigger.

---------- Post added at 01:35 ---------- Previous post was at 00:48 ----------

I decided that this is a better way of doing the hint.

hintSilent parseText format["<t size='2.25' color='#40FF00'>Command Mission Status. <t size='1.25' color='#81F7F3'><br />Completed Missions will reward support assets.<br /><br /></t><t size='1.00' color='#FF8000'>Capture AAC Airfield <t size='1.00' color='#F7FE2E'>%1<br /><t size='1.00' color='#FF8000'>Seek and Destroy Large OA <t size='1.00' color='#F7FE2E'>%2<br /><t size='1.00' color='#FF8000'>Destroy Power Plant <t size='1.00' color='#F7FE2E'>%3<br /><t size='1.00' color='#FF8000'>Annex Panochori <t size='1.00' color='#F7FE2E'>%4",triggerActivated test1,triggerActivated test2,triggerActivated mis3,triggerActivated mis4];

Now is there any way to change the True/False output to something else?

Like instead of saying "Capture AAC Airfield false"

It could say "Capture AAC Airfield Not completed."

And when its completed ""Capture AAC Airfield Support Assets Available"

Thanks

---------- Post added at 02:05 ---------- Previous post was at 01:35 ----------

Anything wrong with the syntax here? Because I cant get the Mortar Script to fire.

_tr2 = createTrigger ["EmptyDetector", getPos Player];

_tr2 setTriggerArea [0, 0, 0, true];

_tr2 setTriggerText "MORTAR FIRE SUPPORT";

_tr2 setTriggerTimeout [0, 0, 0, False];

_tr2 setTriggerType "NONE";

_tr2 setTriggerActivation ["BRAVO", "PRESENT",false];

_tr2 setTriggerStatements ["this", "null = [10, Sh_120mm_HE, 30, 10, 3, 500, west] execVM "support/Mortar.sqf";",""];

Any ideas?

Share this post


Link to post
Share on other sites
Anything wrong with the syntax here? Because I cant get the Mortar Script to fire.

_tr2 = createTrigger ["EmptyDetector", getPos Player];

_tr2 setTriggerArea [0, 0, 0, true];

_tr2 setTriggerText "MORTAR FIRE SUPPORT";

_tr2 setTriggerTimeout [0, 0, 0, False];

_tr2 setTriggerType "NONE";

_tr2 setTriggerActivation ["BRAVO", "PRESENT",false];

_tr2 setTriggerStatements ["this", "null = [10, Sh_120mm_HE, 30, 10, 3, 500, west] execVM "support/Mortar.sqf";",""];

Any ideas?

Check your quotes again...

Share this post


Link to post
Share on other sites

Anything wrong with the syntax here? Because I cant get the Mortar Script to fire.

_tr2 = createTrigger ["EmptyDetector", getPos Player];

_tr2 setTriggerArea [0, 0, 0, true];

_tr2 setTriggerText "MORTAR FIRE SUPPORT";

_tr2 setTriggerTimeout [0, 0, 0, False];

_tr2 setTriggerType "NONE";

_tr2 setTriggerActivation ["BRAVO", "PRESENT",false];

_tr2 setTriggerStatements ["this", "null = [10, Sh_120mm_HE, 30, 10, 3, 500, west] execVM "support/Mortar.sqf";",""];

Any ideas?

Some things do not make a lot of sense in your code:

1.) As JShock already suggested, check your quotes. This is wrong:

_tr2 setTriggerStatements ["this", "null = [10, Sh_120mm_HE, 30, 10, 3, 500, west] execVM "support/Mortar.sqf";",""];

Correct would be:

_tr2 setTriggerStatements ["this", "0 = [10, 'Sh_120mm_HE', 30, 10, 3, 500, west] execVM 'support/Mortar.sqf';",""];

You may wanna use some syntax highlighting as that can help you finding the most obvious errors like parantheses and quote errors.

And by the way, other than in other scripting and programming languages, "null" does not exist in SQF. Hence, assigning something to "null" is the same as assigning it to any other global variable like "myVar" or whatever you wanna call it.

2.)

_tr2 setTriggerArea [0, 0, 0, true];

This line means, you trigger has a non-existent area, meaning your activation condition:

_tr2 setTriggerActivation ["BRAVO", "PRESENT",false];

will never be true. So you need to set a width and a height for the trigger area (first two parameters of setTriggerArea).

3.)

_tr2 setTriggerType "NONE";

There's no need to set the type to "NONE" as that is the default. You only need to do this, if you've set it to something else before.

4.)

_tr2 setTriggerTimeout [0, 0, 0, False];

Same issue as with your setTriggerType statement. A timeout of 0 is set by default. If you want immediate execution of the activation statement, just don't mess with it.

So in the end, this is what your trigger creation code should look like:

_tr2 = createTrigger ["EmptyDetector", getPos Player];
_tr2 setTriggerArea [10, 10, 0, true];
_tr2 setTriggerText "MORTAR FIRE SUPPORT";
_tr2 setTriggerActivation ["BRAVO", "PRESENT", false];
_tr2 setTriggerStatements ["this", "0 = [10, 'Sh_120mm_HE', 30, 10, 3, 500, west] execVM 'support/Mortar.sqf';",""];

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites
instead of using and try &&

Both should work in sqf.

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  

×