Jump to content
Sign in to follow this  
frag

Embarrassing IF-THEN-ELSE question

Recommended Posts

I am almost pulling my hair out.

I am playing around with an If-Then-Else condition for an hour now and cannot make it works. I made few test and I can’t even make the simplest one to work. (In a sqf file)

Entance1 being a building, if I do this it works correctly

_d = getdammage entrance1;

hint format ["%1",_d];

if (_d<1) then{hint "not dead"} else {titletext["Dead","Plain"]};

But if I do it this way (different indentation), it behaves really strangely (I receive both the hint and the title cut, meaning that both the If and the Else parts are executed.

_d = getdammage entrance1;

hint format ["%1",_d];

if (_d<1) then

{

hint "not dead"

}

else

{

titletext["Dead","Plain"]

};

I tried to put ; at the end of both the hint and the titletext lines …resulting in the same effect.

Am I stupid or I am missing something? I looked at many scripts without understanding what I am doing badly.

ps: I am using Arma Edit 1.3 as the editor

Share this post


Link to post
Share on other sites

Try this:

_d = getdammage entrance1;

hint format ["%1",_d];

if (_d<1) then

{

hint "not dead";

}

else

{

titletext["Dead","Plain"];

};

incase you didn't notice a difference, its semicolon ( ; ) in the bolded part

Share this post


Link to post
Share on other sites
Try this:

_d = getdammage entrance1;

hint format ["%1",_d];

if (_d<1) then

{

hint "not dead";

}

else

{

titletext["Dead","Plain"];

};

incase you didn't notice a difference, its semicolon ( ; ) in the bolded part

I tried it also (look at the end of my original message). I wonder if it could not be a bug with the "hint" call or such. I will make further testing tonight, but I have to say that I am really tired playing around a simple if.

I wonder if one of you guys could try this out for me and tell me if you have the same result.

Share this post


Link to post
Share on other sites

When you say you get both hint and titletext, do you mean you see the damage or the "not dead" text?

_d = getdammage entrance1;
if (_d < 1) then {
 hint "not dead";
} else {
 titletext["Dead","Plain"];
};

Share this post


Link to post
Share on other sites
You use exec or execVM?

[] exec "scripts\test.sqf"

---------- Post added at 05:10 PM ---------- Previous post was at 05:09 PM ----------

When you say you get both hint and titletext, do you mean you see the damage or the "not dead" text?

_d = getdammage entrance1;
if (_d < 1) then {
 hint "not dead";
} else {
 titletext["Dead","Plain"];
};

I see the hint"Not dead" appearing and the title text as well. Considering it is an If-Then-Else condition, I should see only one.

Share this post


Link to post
Share on other sites
[] exec "scripts\test.sqf"

That's your problem. Use execVM next time.

Share this post


Link to post
Share on other sites

use execVM

exec thinks your running a SQS script, even if it's called sqf. sqs has a different format. which is why when in a single line it worked.

Share this post


Link to post
Share on other sites
That's your problem. Use execVM next time.
use execVM

exec thinks your running a SQS script, even if it's called sqf. sqs has a different format. which is why when in a single line it worked.

You are the dudes!

Thanks a lot! It makes sense! I will try it on later on tonight.

But is the execVM will run asynchronously? I guess that if I have to keep the thing synchronous I will have to change my syntax in the script to use exec instead of execvm.

Thanks again guys, this forum is a bless.

Share this post


Link to post
Share on other sites

You can just use call to run it in the same thread if you need to make sure something is done asap. Or you can start a new one with execvm and add a waituntil at the start to wait whatever is needed.

Share this post


Link to post
Share on other sites
You are the dudes!

Thanks a lot! It makes sense! I will try it on later on tonight.

But is the execVM will run asynchronously? I guess that if I have to keep the thing synchronous I will have to change my syntax in the script to use exec instead of execvm.

Thanks again guys, this forum is a bless.

By the way I tested it yesterday night and it was in fact my problem.

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  

×