blasturbator 10 Posted April 9, 2014 (edited) Question number 1: If for example i had a for loop that went something like this: for "_x" from 0 to (paramsArray select 1) do { vehicle = createVehicle [etc etc]; }; And i replaced "vehicle" with "vehicle(_x)" would i get sequentially named vehicles? i.e. vehicle1, vehicle2, vehicle3, ~. Question number 2: I want to display the status of an objective with a hint which is part of an eventhandler but my current attempt just breaks the script. This is the one i'm using: hint format ["BLUFOR have destroyed a cache! ", INS_west_score, "/", (paramsArray select 1)]; Which i intended to read as "BLUFOR have destroyed a cache! score/total ", score being the amount killed (tracked elsewhere) and total being the total number (defined elsewhere). What would be the correct format for me to achieve the above? Thanks for taking the time to read :) Edited April 9, 2014 by Blasturbator Share this post Link to post Share on other sites
Magirot 14 Posted April 9, 2014 For question 1, you have to use call compile format ["vehicle%1 = createVehicle [etc etc];", _x]; otherwise it'll mix different datatypes and stuff. Question 2, what you want is hint format ["BLUFOR have destroyed a cache! %1/%2", INS_west_score, (paramsArray select 1)]; Check the documentation of format: formatString: String - a string containing text and/or references to the variables listed below in the array. The references appear in the form of %1, %2 etc. Share this post Link to post Share on other sites
blasturbator 10 Posted April 10, 2014 (edited) Thank you very much Magirot. :D If i wanted to call on the vehicles from question 1 at random could i do something like this? _vehicle = vehicle(random(0+(paramsArray select 1))) Edited April 10, 2014 by Blasturbator not enough smileys Share this post Link to post Share on other sites
Magirot 14 Posted April 10, 2014 Nope, again, you can't combine identifiers like that, but you can use compile in the same fashion as above: call compile format ["_vehicle = vehicle%1", random (0+(paramsArray select 1))]; Share this post Link to post Share on other sites
blasturbator 10 Posted April 10, 2014 (edited) Okay i think i understand now, thanks again :) edit: Evidently i don't understand it enough, I'm trying to get this snippet of code INS_fncache = { for "_x" from 0 to (paramsArray select 1) step 1 do { if (count INS_marker_array > 0) then { {deleteMarker _x} forEach INS_marker_array}; publicVariable "INS_marker_array"; _cities = call SL_fnc_urbanAreas; _cacheTown = _cities call BIS_fnc_selectRandom; _cacheBuildings = _cacheTown call SO_fnc_findHouse; // Pull the array and select a random building from it. _targetBuilding = _cacheBuildings select (random((count _cacheBuildings)-1)); // Take the random building from the above result and pass it through gRBP function to get a single cache position _cachePosition = [_targetBuilding] call getRandomBuildingPosition; // Create the cache at the random marker position cache = createVehicle ["Box_East_WpsSpecial_F", _cachePosition, [], 0, "None"]; clearMagazineCargoGlobal cache; clearWeaponCargoGlobal cache; // Add event handlers to the cache cache addEventHandler ["handleDamage", { if ((_this select 4) == "SatchelCharge_Remote_Mag") then { cache setDamage 1 } else { if ((_this select 4) == "DemoCharge_Remote_Mag") then { cache setDamage 1 } else { cache setDamage 0 }; }; }]; cache addMPEventHandler ["MPKilled", {_this spawn INS_fncscore}]; // Move the Cache to the above select position cache setPos _cachePosition; publicVariable "cache"; if (!isMultiplayer) then { //debug to see where box spawned is if not multiplayer _m = createMarker [format ["box%1",random 1000],getposATL cache]; _m setMarkerShape "ICON"; _m setMarkerType "mil_dot"; _m setMarkerColor "ColorBlue"; }; }; }; to work with every "cache" replaced with a sequentially numbered, "cache1" "cache2" etc, for each iteration of the loop. I just cannae do it :/ This line confuses me the most, the rest i understand kind of but i can't figure out how to deal with this: _m = createMarker [format ["box%1",random 1000],getposATL cache]; Edited April 11, 2014 by Blasturbator Share this post Link to post Share on other sites
blasturbator 10 Posted April 11, 2014 Bump because i need to get this working before i can fix other bugs in my mission ;-; Share this post Link to post Share on other sites
Magirot 14 Posted April 11, 2014 I guess in that case you could use a quite humongous call compile format: INS_fncache = { for "_x" from 0 to (paramsArray select 1) step 1 do { if (count INS_marker_array > 0) then { {deleteMarker _x} forEach INS_marker_array}; publicVariable "INS_marker_array"; _cities = call SL_fnc_urbanAreas; _cacheTown = _cities call BIS_fnc_selectRandom; _cacheBuildings = _cacheTown call SO_fnc_findHouse; // Pull the array and select a random building from it. _targetBuilding = _cacheBuildings select (random((count _cacheBuildings)-1)); // Take the random building from the above result and pass it through gRBP function to get a single cache position _cachePosition = [_targetBuilding] call getRandomBuildingPosition; call compile format [" cache%1 = createVehicle ['Box_East_WpsSpecial_F', _cachePosition, [], 0, 'None']; clearMagazineCargoGlobal cache%1; clearWeaponCargoGlobal cache%1; cache%1 addEventHandler ['handleDamage', { if ((_this select 4) == 'SatchelCharge_Remote_Mag') then { cache setDamage 1 } else { if ((_this select 4) == 'DemoCharge_Remote_Mag') then { cache setDamage 1 } else { cache setDamage 0 }; }; }]; cache%1 addMPEventHandler ['MPKilled', {_this spawn INS_fncscore}]; cache%1 setPos _cachePosition; publicVariable 'cache%1'; if (!isMultiplayer) then { _m = createMarker [box%1, getposATL cache%1]; _m setMarkerShape 'ICON'; _m setMarkerType 'mil_dot'; _m setMarkerColor 'ColorBlue'; }", _x]; }; }; But I'm not sure you actually need to declare a separate identifier for each of them? Couldn't you just use local variables and then keep track with the event handlers you add? Share this post Link to post Share on other sites
blasturbator 10 Posted April 12, 2014 How would i use call compile format for a public variable? i tried call compile format ["publicVariable "cache%1";", _x]; and it didnt work :( Share this post Link to post Share on other sites
Magirot 14 Posted April 12, 2014 If you want to use quotation marks inside a string, use either ' or "". call compile format ["publicVariable 'cache%1'", _x]; //or: call compile format ["publicVariable ""cache%1""", _x]; Share this post Link to post Share on other sites
blasturbator 10 Posted April 12, 2014 (edited) Okay i'm slowly working things out >.< damn there are so many questions to ask. The above works okay thanks again. The next issue is that I have a script which calls on those variables but randomly, using this line call compile format ["_cache = cache%1", random (0+(paramsArray select 1))]; However this does not seem to work, is _cache being randomised every single time it is mentioned in the script or just once at the start? full script here private ["_i","_sign","_sign2","_radius","_cache","_pos","_mkr","_range","_intelRadius"]; hint format ["You picked up an %1 case",(_this select 0)]; //deleteVehicle (_this select 0); //deleteVehicle (_this select 1); call compile format ["_cache = cache%1", random (0+(paramsArray select 1))]; _intelRadius = 500; _i = 0; while{ (getMarkerPos format["%1intel%2", _cache, _i] select 0) != 0} do { _i = _i + 1; }; _sign = 1; if (random 100 > 50) then { _sign = -1; }; _sign2 = 1; if (random 100 > 50) then { _sign2 = -1; }; _radius = _intelRadius - _i * 50; if (_radius < 50) then { _radius = 50; }; _pos = [(getPosATL _cache select 0) + _sign *(random _radius),(getPosATL _cache select 1) + _sign2*(random _radius)]; _mkr = createMarker[format["%1intel%2", _cache, _i], _pos]; _mkr setMarkerType "hd_unknown"; _range = round sqrt(_radius^2*2); _range = _range - (_range % 50); _mkr setMarkerText format["%1m", _range]; _mkr setMarkerColor "ColorRed"; _mkr setMarkerSize [0.5,0.5]; because if every single _cache is different then that is obviously why it isnt working, if not then i don't know where to begin. Edited April 13, 2014 by Blasturbator Share this post Link to post Share on other sites
Magirot 14 Posted April 13, 2014 (edited) However this does not seem to work, is _cache being randomised every single time it is mentioned in the script or just once at the start? It's randomised every time. If you want to get a random number that stays the same throughout the script/scope (though still different for each player executing the script), assign it to a variable and refer to it afterwards. A random number also is a decimal number like "9.954", so you might want to round or floor it. _randomcache = round (random (0 + (paramsArray select 1))); The wiki article on random says: x=round(random 5) will return 0,1,2,3,4 or 5. (non-uniform distribution, 0 and 5 are half as likely to be selected than any of the other numbers)x=floor(random 5) will return 0,1,2,3 or 4. (uniform distribution, all numbers have the same probability of being selected) Edit: Wait, I misread, let me reread your script. The issue is probably that local variables are not passed outside the compile. You either have to use a global variable, like: call compile format ["randomcache = cache%1", round (random (0 + (paramsArray select 1)))]; or create an array of the cache names during the cache creation script, and call from there. Edited April 13, 2014 by Magirot Share this post Link to post Share on other sites