Jump to content
Sign in to follow this  
Holyman

Problem with IF ( a == b)

Recommended Posts

Hi All. Long time listener, first time caller here.

I really have spent the last two hours searching all over for a solution, but have now concluded that the answer to my problem is so simple, no-one has ever needed assistance with it before...

I'm putting together a recruitment script, and I'm just trying to fire some actions conditional on a string passed through with the script call.

I am calling the script with the following (from within another script, btw):

["A"] execVM "Recruit.sqf";

And the (stripped down to try and solve this particular problem) script is:

_g = _this select 0;

hint format ["G is %1", _g];

sleep 3;

if (_g == "A") then 
{
hint "The If Fired...";
       sleep 3;
};

hint "Script End";

exit

The problem I have is that the IF condition just won't fire, and I can't figure out why.

(Obviously the hints are there for debugging purposes.)

I have tried passing through a number rather than a string, and that doesn't work either. So I'm pretty sure it has something to do with the == operator.

I KNOW this must be just a simple syntax shortfall on my part, but I would really appreciate some guidance.

If I don't go to bed right now, my wife will divorce me, so I have to call it quits for the night. But I'll really appreciate any help anyone can offer.

Peace

Share this post


Link to post
Share on other sites

Is the script firing at all?

Make sure you are using

[b]_handle =[/b] ["A"] execVM "Recruit.sqf";

The script fired perfectly when I tested it on the init line of a unit.

Share this post


Link to post
Share on other sites

Copied your entire script, ran it from init.sqf using

["A"] execVM "test.sqf"

it ran perfectly.

Also, the exit command doesn't do anything in SQF, it's an old SQS command.

Share this post


Link to post
Share on other sites

Put an else after the if and check if that fires. If neither the then nor the else parts are fired, but the script still continues to run, then it means the condition of the if has some kind of null or undefined variable.

Also exit at the end of an sqf script doesn't do anything useful...

If you're calling a script from another script then you don't need to do what xPaveway is suggesting. The only 2 reasons to save the script handle are:

1. If called from editor object code (init line, trigger, etc.) the game requires it.

2. It can be used to have the calling script check if the called script ended.

Other than that there is shouldn't be any need to save the handle.

Anyway, I just ran a test:

init.sqf:

["A"] execVM "Recruit.sqf";

recruit.sqf:

_g = _this select 0;

hint format ["G is %1", _g];

sleep 3;

if (_g == "A") then 
{
hint "The If Fired...";
       sleep 3;
};

hint "Script End";

exit

And I got all 3 hints.

Share this post


Link to post
Share on other sites

Thanks very much for the responses guys.

It was helpful to have the doubt removed that my code was the problem.

Turns out that all I needed to do was re-boot... :d:

Either that or the rest my PC had overnight did the job. Or maybe it was the rest that *I* had...

Still, if nothing else, I have learned that I can drop all the "exit" statements from my scripts, which has been a force of habit since OFP days. :)

Thanks again, and I promise I'll drink more coffee before I next think about cluttering up the Forum with a pointless thread.

Peace

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  

×