Call Local Variable to Variable outside of Parent scope?

  • Offline Mokey
  • Fractured Wasteland
  • Elite
  • ******
  • Posts: 606
  • Https://Fractured-Gaming.com

Call Local Variable to Variable outside of Parent scope?

« posted: May 17, 2018, 02:56 AM »
Hey all,

This may be more of a Rev or veteran A3W/Arma coder question  I'm working on a mission. I can't seem to get this to work. I'm trying to call "_moneyAmount" from MoneyMissions to a bit for a success exec that me and another guy have been working on. But my problem is, I cannot seem to get the variable "_moneyAmount" to pass outside of the scope of "_setupVars" Function.

If anyone can help me out, it would be great.

The Function:
(I can get _moneyAmount to return a proper value from within the scope)
Code: [Select]
_setupVars =
{
_MoneyShipment = selectRandom
[
// Easy
[
"Small Smuggler Shipment", // Marker text
60000, 80000, 100000, // Money
[
[ // NATO convoy
["B_MRAP_01_hmg_F", "B_MRAP_01_gmg_F", "O_T_LSV_02_armed_F"], // Veh 1
["B_MRAP_01_hmg_F", "B_MRAP_01_gmg_F", "O_T_LSV_02_armed_F"] // Veh 2
],
[ // CSAT convoy
["O_MRAP_02_hmg_F", "O_MRAP_02_gmg_F", "B_T_LSV_01_armed_F"], // Veh 1
["O_MRAP_02_hmg_F", "O_MRAP_02_gmg_F", "B_T_LSV_01_armed_F"] // Veh 2
],
[ // AAF convoy

["I_MRAP_03_hmg_F", "I_MRAP_03_gmg_F", "I_LT_01_cannon_F"], // Veh 1
["I_MRAP_03_hmg_F", "I_MRAP_03_gmg_F", "I_LT_01_AT_F"] // Veh 2

]
]
],
// Medium
[
"Medium Smuggler Shipment", // Marker text
100000, 120000, 140000, // Money
[
[ // NATO convoy
["B_MRAP_01_hmg_F", "B_MRAP_01_gmg_F"], // Veh 1
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F"], // Veh 2
["B_MRAP_01_hmg_F", "B_MRAP_01_gmg_F"] // Veh 3
],
[ // CSAT convoy
["O_MRAP_02_hmg_F", "O_MRAP_02_gmg_F"], // Veh 1
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F"], // Veh 2
["O_MRAP_02_hmg_F", "O_MRAP_02_gmg_F"] // Veh 3
],
[ // AAF convoy
["I_MRAP_03_hmg_F", "I_MRAP_03_gmg_F", "I_LT_01_cannon_F"], // Veh 1
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F"], // Veh 2
["I_MRAP_03_hmg_F", "I_MRAP_03_gmg_F", "I_LT_01_AT_F"] // Veh 3
]
]
],
// Hard
[
"Large Smuggler Shipment", // Marker text
140000, 160000, 180000, // Money
[
[ // NATO convoy
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F", "B_AFV_Wheeled_01_up_cannon_F"], // Veh 1
["B_MBT_01_cannon_F", "B_MBT_01_TUSK_F"], // Veh 2
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F"] // Veh 3
],
[ // CSAT convoy
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F"], // Veh 1
["O_MBT_02_cannon_F", "O_MBT_04_cannon_F"], // Veh 2
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F"] // Veh 3
],
[ // AAF convoy
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F"], // Veh 1
["I_MBT_03_cannon_F"], // Veh 2
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F"] // Veh 3
]
]
],
// Extreme
[
"Heavy Smugglers Shipment", // Marker text
180000, 200000, 220000,// Money
[
[ // NATO convoy
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F", "B_MBT_01_cannon_F", "B_MBT_01_TUSK_F"], // Veh 1
["B_APC_Tracked_01_AA_F", "B_MBT_01_cannon_F", "B_MBT_01_TUSK_F"], // Veh 2
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F", "B_MBT_01_cannon_F", "B_MBT_01_TUSK_F"], // Veh 3
["B_APC_Wheeled_01_cannon_F", "B_APC_Tracked_01_rcws_F", "B_APC_Tracked_01_AA_F", "B_MBT_01_cannon_F", "B_MBT_01_TUSK_F"] // Veh 4
],
[ // CSAT convoy
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F", "O_MBT_02_cannon_F"], // Veh 1
["O_APC_Tracked_02_AA_F", "O_MBT_02_cannon_F", "O_MBT_04_command_F"], // Veh 2
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F", "O_MBT_02_cannon_F"], // Veh 3
["O_APC_Wheeled_02_rcws_v2_F", "O_APC_Tracked_02_cannon_F", "O_APC_Tracked_02_AA_F", "O_MBT_02_cannon_F"] // Veh 4
],
[ // AAF convoy
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F", "I_MBT_03_cannon_F"], // Veh 1
["I_APC_tracked_03_cannon_F", "I_MBT_03_cannon_F"], // Veh 2
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F", "I_MBT_03_cannon_F"], // Veh 3
["I_APC_Wheeled_03_cannon_F", "I_APC_tracked_03_cannon_F", "I_MBT_03_cannon_F"] // Veh 4
]
]
]
];

_missionType = _MoneyShipment select 0;
_moneyAmount = floor (random [_moneyShipment select 1, _moneyShipment select 2,  _moneyShipment select 3]);
_convoys = _MoneyShipment select 4;
_vehChoices = selectRandom _convoys;
_moneyText = format ["$%1", [_moneyAmount] call fn_numbersText];

_vehClasses = [];
{ _vehClasses pushBack selectRandom _x } forEach _vehChoices;
};

Outside of the Scope:
Code: [Select]
_missionMoneyTotal = _moneyAmount;
I noticed in your default wasteland rev has:
Code: [Select]
for "_i" from 1 to 10 do
{
_cash = createVehicle ["Land_Money_F", _lastPos, [], 5, "None"];
_cash setPos ([_lastPos, [[2 + random 3,0,0], random 360] call BIS_fnc_rotateVector2D] call BIS_fnc_vectorAdd);
_cash setDir random 360;
_cash setVariable ["cmoney", _moneyAmount / 10, true];
_cash setVariable ["owner", "world", true];
};
Which is set outside of the scope. But when I try to do it myself... it either says
Code: [Select]
undefined variable in expression _moneyAmount or the code get le broken everywhere.

 
Posts once, edits post 40 times in 60 seconds. STUPID FAT FINGERS!
  • Offline Mokey
  • Fractured Wasteland
  • Elite
  • ******
  • Posts: 606
  • Https://Fractured-Gaming.com

Re: Call Local Variable to Variable outside of Parent scope?

« Reply #1 posted: May 17, 2018, 04:51 AM »
@soulkobk got me hooked up.

Code: [Select]
_missionParseSetupVars = call _setupVars;
Posts once, edits post 40 times in 60 seconds. STUPID FAT FINGERS!
  • Offline Mokey
  • Fractured Wasteland
  • Elite
  • ******
  • Posts: 606
  • Https://Fractured-Gaming.com

Re: Call Local Variable to Variable outside of Parent scope?

« Reply #2 posted: May 18, 2018, 04:40 PM »
Well it seems that this causes the variables to be called 2x which makes no sense seeing how _vehClasses are called the same way and it isn't causing an issue.
Posts once, edits post 40 times in 60 seconds. STUPID FAT FINGERS!
  • Offline AgentRev
  • Developer
  • Veteran
  • ******
  • Posts: 2652

Re: Call Local Variable to Variable outside of Parent scope?

« Reply #3 posted: May 19, 2018, 02:56 AM »
All you have to do is add the variable name in the private array right above _setupVars, like "_nbUnits". It's the very purpose of that line.