anaximandross 34 Posted January 30, 2019 I'm sure this has been asked a million times, but I can't find a solution. I'm trying to take a global variable that is declared in init.sqf, get its value in a separate script, and then change that global value. However, anytime I do that I get an error saying Local Variable in Global Space. How do I fix this? Thanks in advance To be clear, this is a PvE mission, so all players should be able to have access to the public variables. Init.sqf (I commented out my initial global declaration) if (isServer) then { fn_getBuildingstospawnLoot = compile preProcessFileLineNumbers "LootSpawn\fn_LSgetBuildingstospawnLoot.sqf"; LSdeleter = compile preProcessFileLineNumbers "LootSpawn\LSdeleter.sqf"; execVM "LootSpawn\Lootspawner.sqf"; []execVM "dynamix\dynamix.sqf"; []execVM "VehicleSpawn\vehiclespawner.sqf"; missionNamespace setVariable ["GLOBALFOOD",20,true]; missionNamespace setVariable ["CURRENTBASENUMBER",0,true]; }; // GLOBALFOOD = 20; // publicVariable "GLOBALFOOD"; // CURRENTBASENUMBER = 0; // publicVariable "CURRENTBASENUMBER"; BaseClaim.sqf (where the fun happens) if(!isServer) exitWith{}; params ["_marker", "_foodCost","base_num"]; //Counts number of enemies around the desired marker _units = allUnits select {side _x == east && _marker distance2D _x < 100}; _cnt = count _units; private _globalFood = missionNamespace getVariable GLOBALFOOD; //checks to see if the area around the base is clear if(_cnt > 0) then { hint "Clear the area to claim this base!" } //if the area is clear, this allows the player to claim the base else{ if(_gobalFood > _foodcost) then { //calculates the amount of food remaining in food stores _foodremaining = _globalfood - _foodcost; hint format["You have %1 food remaining!",_foodremaining]; GLOBALFOOD = _foodremaining; missionNamespace setVariable ["GLOBALFOOD",_foodremaining,true]; //determines the current base number to be used for other things CURRENTBASENUMBER = base_num; publicVariable "CURRENTBASENUMBER"; //creates a marker at the current base. This is used for AI targetting deleteMarker "CurrentBase"; _currentBaseMarker = createMarker["CurrentBase", getMarkerPos "_marker"]; "CurrentBase" setMarkerColor "ColorBlue"; "CurrentBase" setMarkerText "Home Base"; } }; Share this post Link to post Share on other sites
Mr H. 402 Posted January 30, 2019 I can see a typo here: if(_gobalFood > _foodcost) then {// should be _globalFood Which variable is mentioned in the error message? Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Well...that was a fantastically simple solution. That being said, nothing is happening. There's no marker being created. I'm using a flagpole with addAction to create the marker and claim the base. Here's the code for that: this addAction["Claim Base (10 Food)","BaseFunctions\ClaimBase.sqf",[base_4,10,4]]; this addAction["Claim Base (10 Food)","BaseFunctions\ClaimBase.sqf",["base_4",10,4]]; I have a marker located at the same place named base_4. Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 I've also just added another line to delete marker base_4 once the script is complete and it isn't working at all. //creates a marker at the current base. This is used for AI targetting deleteMarker "CurrentBase"; deleteMarker "base_4"; _currentBaseMarker = createMarker["CurrentBase", getMarkerPos "_marker"]; OK! So it seems that my if statement isn't executing. The comparison between _globalFood > _foodcost is not occurring. Any suggestions? (I tested this by adding hint statements) Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 params ["_marker", "_foodCost","base_num"]; Params parses input argument into array of private variables. That would be where global is in private space. Try removing "base_num" from the params line and define it as either _this select 2; or _this # 2; Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 2 minutes ago, opusfmspol said: params ["_marker", "_foodCost","base_num"]; Params parses input argument into array of private variables. That would be where global is in private space. Try removing "base_num" from the params line and define it as either _this select 2; or _this # 2; I'm going to have several different bases though, so don't I need to be able to pass that so that I can define various attributes of different bases? Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 (edited) It was considered that you needed to pass it in. What I meant is a global variable from input params needs to be defined without using the Params command, because it is not giving a private variable for the command to return define. params ["_marker", "_foodCost"]; base_num = _this select 2; Edited January 30, 2019 by opusfmspol define. I meant define, since return is actually boolean. Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Ok, I'm starting to understand, but I'm not fully there yet. What does the _this select 2; do? select has always confused me. Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 Oldie but goldie: Beginners Guide to Arrays Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Ok Cool! I'll check it out. Also, do you have any idea why my code from the second part isn't executing? else{ if(_globalFood > _foodcost) then { _markPos = getMarkerPos "base_4"; //calculates the amount of food remaining in food stores _foodremaining = _globalfood - _foodcost; hint format["You have %1 food remaining!",_foodremaining]; GLOBALFOOD = _foodremaining; missionNamespace setVariable ["GLOBALFOOD",_foodremaining,true]; hint "New Home Base Claimed!"; //determines the current base number to be used for other things CURRENTBASENUMBER = base_num; publicVariable "CURRENTBASENUMBER"; //creates a marker at the current base. This is used for AI targetting deleteMarker "CurrentBase"; deleteMarker "base_4"; hint "marker deleted"; _currentBaseMarker = createMarker["CurrentBase", _markPos]; "CurrentBase" setMarkerColor "ColorBlue"; "CurrentBase" setMarkerText "Home Base"; "CurrentBase" setMarkerType "mil_circle"; } }; And to be clear, I'm no longer receiving the local var in global space error. My script just isn't working lol Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 //Counts number of enemies around the desired marker _units = allUnits select {side _x == east && _marker distance2D _x < 100}; _cnt = count _units; This line appears in error. Select doesn't use the magic variable "_x", count and forEach do. Try this: //Counts number of enemies around the desired marker _units = []; {if (side _x == east && {_marker distance2D _x < 100}) then {_units pushBack _x};} forEach allUnits; _cnt = count _units; --- Edit: Larrow corrects in post #41, that Select command does use magic "_x" variable in alternative syntax. Much appreciated. 1 Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 I made the change and it still isn't working unfortunately. Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 Clear the .rpt log and run the mission once. What does .rpt log report as the issue? Also might try expanding the params and adding debug lines to catch bad values that pass in. if(!isServer) exitWith{}; params [ ["_marker","",[""]], ["_foodCost",99999,[0]] ]; if (_marker == "") exitWith {diag_log format ["Debug Error (BaseClaim.sqf): Invalid marker passed in params (%1)",_this];}; if (_foodCost == 99999) exitWith {diag_log format ["Debug Error (BaseClaim.sqf): Invalid food cost passed in params (%1)",_this];}; Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Here's a copy my .rpt if that's any help. Around line 7980 is where I start to see issues. https://pastebin.com/Z6Pw5T0T. Whhops, I have no clue how that got there. Wrong one. See below Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Ok, here's my .rpt after clearing it. I don't see anything too important in here, but perhaps you will. https://pastebin.com/xE8kUtBu Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 Warning Message: File C:\Users\chase\Documents\Arma 3 - Other Profiles\Harbor\missions\State%20of%20Disorder.Malden\Compositions\foodstor_s.sqf, line 1: Config: .: '[' encountered instead of ']' This keeps repeating. Check your coding in file "foodstor_s.sqf". Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 That's an array that's being used by the objectMapper. It was created by bethesda. i'm not sure why its throwing that, as it works properly. Here it is though if you'd like to look. /* Grab data: Mission: Compositions World: VR Anchor position: [1107.01, 3362.12] Area size: 50 Using orientation of objects: no */ [ ["VR_Area_01_square_4x4_yellow_F",[0.148193,0.095459,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[-0.0981445,-1.10815,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[-0.780762,-0.928467,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_F",[0.574585,1.21509,0],0,1,0,[],"","",true,false], ["Land_WoodenTable_large_F",[-0.337036,-1.30249,0],271.845,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[0.355713,-1.45874,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[-0.614136,-1.39819,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[-0.209961,-1.52515,0],0,1,0,[],"","",true,false], ["Land_WoodenTable_large_F",[1.43872,0.611816,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_F",[1.13318,0.636475,0],0,1,0,[],"","",true,false], ["Land_LiquidDispenser_01_F",[1.08923,-0.228027,0],257.004,1,0,[],"","",true,false], ["Land_Shovel_F",[-0.738159,1.25586,0],277.764,1,0,[],"","",true,false], ["Land_Pot_01_F",[-0.755127,1.46582,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[-1.10596,-1.27075,0],0,1,0,[],"","",true,false], ["Land_FoodContainer_01_White_F",[0.577393,1.63672,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.59338,0.367676,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.66663,0.20459,0],0,1,0,[],"","",true,false], ["Land_Can_V2_F",[1.31775,1.10156,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_Flower_F",[0.0153809,-1.02612,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.67834,0.589111,0],45.9229,1,0,[],"","",true,false], ["Land_FlowerPot_01_F",[1.76807,-0.110107,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.77661,0.372314,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.81641,0.222412,0],0,1,0,[],"","",true,false], ["Land_RiceBox_F",[1.80627,0.477295,0],0,1,0,[],"","",true,false], ["Land_Pumpkin_01_F",[1.19568,1.44287,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_Flower_F",[-0.730591,-1.11475,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_F",[1.57324,1.21021,0],0,1,0,[],"","",true,false], ["Land_BakedBeans_F",[1.82971,0.857178,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_F",[-1.11768,-1.66724,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_Flower_F",[0.477783,-1.53784,0],0,1,0,[],"","",true,false], ["Land_FlowerPot_01_Flower_F",[-0.176636,-1.65381,0],0,1,0,[],"","",true,false], ["Land_CerealsBox_F",[1.64941,1.5,0],0,1,0,[],"","",true,false], ["Land_CerealsBox_F",[1.63818,1.58398,0],0,1,0,[],"","",true,false] ] Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Could the issue be in how I'm calling it? I've got a flagpole with this in its init: this addAction["Claim Base (10 Food)","BaseFunctions\ClaimBase.sqf",[base_4,10]]; Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 Seems fine, so the question becomes whether there is an error in the calling script. I presume this is a return, i.e. another script calls and this gets returned back to the call. Review the calling script, particularly the call itself. The error is saying that for some reason an " ] " is expected, but it's encountering " [ " instead (first line of the return). Edit -- oops, we cross-posted at the same time 1 Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Ok, so this is on a post this addAction["Build a small food storage", "Compositions\assembler.sqf"]; That calls assembler.sqf: if(!isServer) exitWith {}; params ["_facilityPositon","_facilityType"] _storPosit = getMarkerPos "_facilityPositon"; if (_facilityType == "foodS") then { 0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper; }; if (_facilityType == "foodL") then { 0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper; }; if (_facilityType == "workshopS") then { 0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper; }; if (_facilityType == "workshopL") then { 0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper; }; I've made a few changes to this script but the error remains the same. This script then calls foodstor_s.sqf. Unfortunately, I again don't see any errors either. Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 params ["_facilityPositon","_facilityType"] _storPosit = getMarkerPos "_facilityPositon"; Should be: params ["_facilityPositon","_facilityType"] _storPosit = getMarkerPos _facilityPositon; . . . and param "_facilityPositon" should be a string passed in, specifically, the marker name. this addAction["Claim Base (10 Food)","BaseFunctions\ClaimBase.sqf",[base_4,10]]; You removed the "base_num" value (was [base_4,10,4] previously). The prior post with base_num = _this select 2 was intended to catch and define it being passed in. Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Ohhhhh ok! I'll give that a shot again. Thanks for all the help. This is my first major scripting attempt, so I'm making all kinds of mistakes. Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 I added in this hint to output the number of troops in the area, but nothing happens. Does that mean that this script isn't being executed at all? if(isServer) exitWith{}; //params ["_marker", "_foodCost"]; if(!isServer) exitWith{}; //add a new parameter for array of markers being passed into createBasePlots params [ ["_marker","",[""]], ["_foodCost",99999,[0]] ]; if (_marker == "") exitWith {diag_log format ["Debug Error (BaseClaim.sqf): Invalid marker passed in params (%1)",_this];}; if (_foodCost == 99999) exitWith {diag_log format ["Debug Error (BaseClaim.sqf): Invalid food cost passed in params (%1)",_this];}; //Counts number of enemies around the desired marker //Counts number of enemies around the desired marker _units = []; {if (side _x == east && {_marker distance2D _x < 100}) then {_units pushBack _x};} forEach allUnits; _cnt = count _units; hint format["Count:",_cnt]; {rest of code} Share this post Link to post Share on other sites
opusfmspol 282 Posted January 30, 2019 if(isServer) exitWith{}; //params ["_marker", "_foodCost"]; if(!isServer) exitWith{}; Correct. It's exiting script whether server or not server. Share this post Link to post Share on other sites
anaximandross 34 Posted January 30, 2019 Mother of god...that was a dumb mistake! Ok! Well, now that the script is actually executing, its giving me an error that its expecting a number but getting an object. It says the issue is in line8, which is the parameters And thank you so much for your time! I greatly appreciate it. Share this post Link to post Share on other sites