Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Embarrassing IF-THEN-ELSE question

  1. #1

    Embarrassing IF-THEN-ELSE question

    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

  2. #2
    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

  3. #3
    Quote Originally Posted by Mr_Centipede View Post
    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.

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

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

  5. #5
    You use exec or execVM?

  6. #6
    Quote Originally Posted by Mike84 View Post
    You use exec or execVM?
    [] exec "scripts\test.sqf"

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

    Quote Originally Posted by shk View Post
    When you say you get both hint and titletext, do you mean you see the damage or the "not dead" text?

    Code:
    _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.

  7. #7
    Quote Originally Posted by frag View Post
    [] exec "scripts\test.sqf"
    That's your problem. Use execVM next time.

  8. #8
    Staff Sergeant
    Join Date
    Jul 16 2009
    Location
    San Antonio, Tx.
    Posts
    208
    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.

  9. #9
    Quote Originally Posted by Mike84 View Post
    That's your problem. Use execVM next time.
    Quote Originally Posted by Big_Daddy View Post
    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.

  10. #10
    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •