Setting variables within nested control structures

2 posts in this topic

Hey all, banging my head on this one.  I'm trying to set some variables based on set of control structures that scan an array of arrays until they find ones matching values from a series of list boxes.  Once the search finds the matching array, I need to pull other values from that array and assign them to variables to be used elsewhere in the function.  However, on trying to log these, they return the value of "any".  When I run the log on them within the control structure, I get the proper string values.

Have a look:


    for "_i" from 0 to (count APOC_AA_Drops)-1 do {
      _Category = (APOC_AA_Drops select _i) select 0; //Grabs the string of the drop category ie: "Vehicles" or "Supplies" or "Lawn Gnomes"
      if (_Category == _CategorySelection) then
        diag_log format["AAA - _Category line 179 = %1",_Category];
          _Selection = _x select 1;
          if (_DropSelection == _Selection) then
            diag_log format["AAA - _Selection line 184 = %1",_Selection];
            _DropDesc = _x select 0;
            _DropPrice = _x select 2;
            _DropType = _x select 3;
        } forEach ((APOC_AA_Drops select _i) select 1);
    diag_log format["AAA - _DropDesc = %1, _DropPrice = %2, _DropType = %3",_DropDesc,_DropPrice, _DropType];


I'm guessing what's happening is that the variables' scopes are only within that structure, and not available to the rest of the function.  Thoughts?

Share this post

Link to post
Share on other sites

Reading is fundamental.

Proper variable initialization was the issue at hand.  I was lazy and didn't properly set values or declare the variable prior to using them within the control structures.  Therefore their scope was limited to the structure level at which they were initialized.  

Changed this, and now problem solved.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.