Jump to content
Sign in to follow this  
Hank Rearden

HELP! Logic or Syntax Error? (script)

Recommended Posts

Simple script. Basically everytime I call it, I want the script to check for the status of the objective variables obj_0, obj_1 etc. and skip forward through the nested else/if/then structure to find the proper script based on which objective variables have been fulfilled. I'm aware I could call this from triggers but due to another script I'm using, this is the method I'd like to use to jump through the list, check vs. public variables and assign the right objective based on where in the if/then/else argument structure the conditions are met. Just headaching over the logic and unsure if it should be if {obj_0 = false} or if {isNull "obj_0"}. Whatever I did wrong, it's not working yet so if you can think of something, let me know.

if isServer then {
if {obj_0 = false}
then
   {
   "0" objStatus "DONE";
   MAG_tskObj0 setTaskState "SUCCEEDED";
   player setCurrentTask MAG_tskObj1;
   obj_0 = true;
   publicVariable "obj_0";
   }
else
   {
   if {obj_0}
   then
       {
       "1" objStatus "DONE";
       MAG_tskObj1 setTaskState "SUCCEEDED";
       player setCurrentTask MAG_tskObj2;
       obj_1 = true;
       publicVariable "obj_1";
       }
   else
       {
       if {obj_0 && obj_1}
       then
           {
           "2=" objStatus "DONE";
           MAG_tskObj2 setTaskState "SUCCEEDED";
           player setCurrentTask MAG_tskObj3;
           obj_2 = true;
           publicVariable "obj_2";
           }
       else
           {
           if {obj_0 && obj_1 && obj_2}
           then
               {
               "3" objStatus "DONE";
               MAG_tskObj3 setTaskState "SUCCEEDED";
               player setCurrentTask MAG_tskObj4;
               obj_3 = true;
               publicVariable "obj_3";
               }
           else
               {
               if {obj_0 && obj_1 && obj_2 && obj_3}
               then
                   {
                   "4" objStatus "DONE";
                   MAG_tskObj4 setTaskState "SUCCEEDED";
                   obj_4 = true;
                   publicVariable "obj_4";
               };
           };
       };
   };
};

Share this post


Link to post
Share on other sites

wrong

if {foo} then {bar}

use

if (foo) then {bar}

Share this post


Link to post
Share on other sites

Yup. Thank you. Also needed to define the variables in my Init.

Wound up doing this in the Init:

if (isNil "OBJ_0") then {OBJ_0 = false;};
if (isNil "OBJ_1") then {OBJ_1 = false;};
if (isNil "OBJ_2") then {OBJ_2 = false;};
if (isNil "OBJ_3") then {OBJ_3 = false;};
if (isNil "OBJ_4") then {OBJ_4 = false;};

And restructuring the script like this:

if (isServer) then {

   if (obj_0) 
   then {    
       if (obj_1) 
       then {
           if (obj_2) 
           then {
               if (obj_3) 
               then {
                   if (obj_4) 
                   then {}
           else {    
           "4" objStatus "DONE"; 
           MAG_tskObj4 setTaskState "SUCCEEDED"; 
           obj_4 = true; 
           publicVariable "obj_4";
       };
       }
           else {    
           "3" objStatus "DONE"; 
           MAG_tskObj3 setTaskState "SUCCEEDED"; 
           player setCurrentTask MAG_tskObj3; 
           obj_3 = true; 
           publicVariable "obj_3";
       };
       }
           else {    
           "2" objStatus "DONE"; 
           MAG_tskObj2 setTaskState "SUCCEEDED"; 
           player setCurrentTask MAG_tskObj3; 
           obj_2 = true; 
           publicVariable "obj_2";
       };
       }
           else {    
           "1" objStatus "DONE"; 
           MAG_tskObj1 setTaskState "SUCCEEDED"; 
           player setCurrentTask MAG_tskObj2; 
           obj_1 = true; 
           publicVariable "obj_1";
       };
       }
           else {    
           "0" objStatus "DONE"; 
           MAG_tskObj0 setTaskState "SUCCEEDED"; 
           player setCurrentTask MAG_tskObj1; 
           obj_0 = true; 
           publicVariable "obj_0";
       };
};

Just to clarify, I'm supposed to define the variables at the top of the Init.sqf (before if (isServer) tags?)

Share this post


Link to post
Share on other sites

<cough> squint </cough>

Looks like you also have a missing closing brace at the end.

Share this post


Link to post
Share on other sites

I think that's right.

(That will define the obj_1 etc vars on all machines with the default value.

I.E false)

Though, you later must use publicVariable if you've changed them from the server.(I think you know this already)

Regards,

HRN1992

Share this post


Link to post
Share on other sites

objStatus is an obsolete command. It does nothing in ArmA 2.

Share this post


Link to post
Share on other sites

OMG! Yes, What ST Dux said is right!

In ArmA 2, you have to use : setTaskState

and you need to create a function file to create the tasks..

Better download the

A2B Editor

With this tool, you can easily make objectives/tasks.

A2B Editor on ArmAHolic

Regards,

Haroon1992

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  

×