JeyR 2 Posted November 17, 2018 Helo. I have a seeding problem with the random function that I just can't figure out. while { surfaceIsWater _suitable || count _list > 0} do { while {_spot distance officer_jeff < 1000 || surfaceIsWater _spot} do { _prevStep = _center getPos[ (random 2000), (random 350)]; for "_i" from 0 to 2 do { _step = _prevStep getPos[ (random 2001), (random 351)]; _prevStep = _step; }; _spot = [_step select 0,_step select 1,0]; }; _suitable = [_spot, 0, 300, 20, 0, 0.7, 0] call BIS_fnc_findSafePos; _list = nearestTerrainObjects [_suitable,["TREE","BUILDING","RUIN","ROCK","HOUSE"], _howBig,false]; }; If the script can't find a position that is not a water surface, it restarts BUT the RANDOM functions just keeps giving me the same position every time the cycle ends. I don't understand, is it not supposed to be random? I also tried this with seed using the alternate syntax of random: while { surfaceIsWater _suitable || count _list > 0} do { while {_spot distance officer_jeff < 1000 || surfaceIsWater _spot} do { _prevStep = _center getPos[ (time random 2000), (time random 350)]; for "_i" from 0 to 2 do { _step = _prevStep getPos[ (time random 2001), (time random 351)]; _prevStep = _step; }; _spot = [_step select 0,_step select 1,0]; }; _suitable = [_spot, 0, 300, 20, 0, 0.7, 0] call BIS_fnc_findSafePos; _list = nearestTerrainObjects [_suitable,["TREE","BUILDING","RUIN","ROCK","HOUSE"], _howBig,false]; }; Here is an example output: 15:12:48 "[823.795,10712.5] as _suitable, 56 as count _list, [816.133,10551.5,0] as _spot " 15:12:49 "[820.423,10745.8] as _suitable, 46 as count _list, [816.133,10551.5,0] as _spot " 15:12:50 "[828.004,10684.4] as _suitable, 76 as count _list, [816.133,10551.5,0] as _spot " Any help would be much appreciated. Share this post Link to post Share on other sites
gc8 977 Posted November 17, 2018 Can you please also post the code that prints the output? Share this post Link to post Share on other sites
JeyR 2 Posted November 17, 2018 diag_log format ["%1 %2 %3 ", _suitable,count _list, _spot]; I don't see how is this important. Share this post Link to post Share on other sites
gc8 977 Posted November 17, 2018 Honestly I don't see anything wrong with the output. _spot is only printing the last value you assigned to it Share this post Link to post Share on other sites
JeyR 2 Posted November 17, 2018 I know that the output is correct. Did you read my question? I want to know why the "[ (random 2000), (random 350)]" keeps giving back the same numbers in each cycle ? Share this post Link to post Share on other sites
gc8 977 Posted November 17, 2018 Have you tried putting: systemchat format["_prevStep = %1",_prevStep]; Because I doubt it really gives back same numbers... Share this post Link to post Share on other sites
JeyR 2 Posted November 17, 2018 Yes it does, and if you don't believe it, try it. I can upload the whole file if need be. Share this post Link to post Share on other sites
gc8 977 Posted November 17, 2018 if you put the whole script somewhere I would like to test it Share this post Link to post Share on other sites
JeyR 2 Posted November 17, 2018 https://pastebin.com/dvaUQzZu Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 I get only one print in the log but the numbers are different every time Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 How do you get only 1 print? Here is my output, and I just raw copied my script into pastebin : https://i.gyazo.com/0a4263a9d70009a2ebbe9b1418d6e196.png Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 This is the code I tested with, had to make some modifications because I run the script from init.sqf and there was no _this variable there: officer_jeff = player; _howBig = 11; // _this select 0; missionNamespace setVariable["task_underway",true]; _center = missionNamespace getVariable ["World_center",[5840,5700,0]]; _suitable = [0,0,0]; private ["_step","_prevStep"]; _list = _suitable; _spot = getPos officer_jeff; while { surfaceIsWater _suitable || count _list > 0} do { while {_spot distance (officer_jeff) < 1000 || surfaceIsWater _spot} do { _prevStep = _center getPos[ (random 2000), (random 350)]; for "_i" from 0 to 2 do { _step = _prevStep getPos[ (random 2001), (random 351)]; _prevStep = _step; }; _spot = [_step select 0,_step select 1,0]; }; _suitable = [_spot, 0, 300, 20, 0, 0.7, 0] call BIS_fnc_findSafePos; _list = nearestTerrainObjects [_suitable,["TREE","BUILDING","RUIN","ROCK","HOUSE"], _howBig,false]; diag_log format [">>>>>>>>>>>>>>>>>>>>>>>>>> %1 %2 %3 ", _suitable,count _list, _spot]; }; _marker1 = createMarker ["Marker"+ str _suitable,_suitable]; _marker1 setMarkerType "hd_objective"; Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 _howbig is always more than 100 meters, of course it works with 11. I might have forgot to mention that. Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 Ok I got it printing more with 50 in the _howBig and this is what it printed: 18:25:52 "_spot = [5424.32,2814.91,0]" 18:25:52 "_spot = [6579.24,1790.43,0]" 18:25:52 "_spot = [6060.41,6817.24,0]" 18:25:52 "_spot = [6682.16,6311.07,0]" 18:25:52 "_spot = [7446.01,7323.48,0]" 18:25:52 ">>> [7185.68,7461.17] 0 [7446.01,7323.48,0] " second run: 18:26:13 "_spot = [6449.77,3067.1,0]" 18:26:13 "_spot = [6000.58,4245.9,0]" 18:26:13 ">>> [6037.21,4216.71] 3 [6000.58,4245.9,0] " 18:26:13 ">>> [6245.18,4352.97] 7 [6000.58,4245.9,0] " 18:26:13 ">>> [6033.74,4244.55] 7 [6000.58,4245.9,0] " 18:26:13 ">>> [6024.26,4214.05] 5 [6000.58,4245.9,0] " 18:26:13 ">>> [5954.42,4244.34] 3 [6000.58,4245.9,0] " 18:26:13 ">>> [5902.36,4290.74] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [5932.08,4268.41] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [5923.96,4278.38] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [5869,4270.3] 4 [6000.58,4245.9,0] " 18:26:13 ">>> [6234.19,4349.69] 10 [6000.58,4245.9,0] " 18:26:13 ">>> [6269.02,4344.69] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [5863.95,4260.2] 7 [6000.58,4245.9,0] " 18:26:13 ">>> [5924.03,4258.01] 1 [6000.58,4245.9,0] " 18:26:13 ">>> [5974.62,4262.46] 3 [6000.58,4245.9,0] " 18:26:13 ">>> [5983.3,4359.46] 6 [6000.58,4245.9,0] " 18:26:13 ">>> [6007.38,4256.17] 5 [6000.58,4245.9,0] " 18:26:13 ">>> [5915.53,4280.58] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [6084.11,4323.63] 2 [6000.58,4245.9,0] " 18:26:13 ">>> [5910.75,4262.52] 0 [6000.58,4245.9,0] " Seems to work to me (The _spot is changing) Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 No it doesn't, I can see it clearly. The _spot didn't change in the last 20 cycles [6000.58,4245.9,0]. Don't tell me you don't see it. _spot is supposed to be random, not the same number in each cycle. Get it ? Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 Just now, JeyR said: No it doesn't, I can see it clearly. The _spot didn't change in the last 20 cycles [6000.58,4245.9,0]. Don't tell me you don't see it. _spot is supposed to be random, not the same number in each cycle. Get it ? Of course it's the same in the second print because it prints the last value set for _spot. But in the "_spot = " line all the values assigned to _spot are printed and those vary Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 I can't see it, the 2nd run just printed _spot as [6000.58,4245.9,0] 20 times in a row. What do you mean it varies ? Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 Try with this new test code: officer_jeff = player; _howBig = 50; // _this select 0; missionNamespace setVariable["task_underway",true]; _center = missionNamespace getVariable ["World_center",[5840,5700,0]]; _suitable = [0,0,0]; private ["_step","_prevStep"]; _list = _suitable; _spot = getPos officer_jeff; while { surfaceIsWater _suitable || count _list > 0} do { while {_spot distance (officer_jeff) < 1000 || surfaceIsWater _spot} do { _prevStep = _center getPos[ (random 2000), (random 350)]; for "_i" from 0 to 2 do { _step = _prevStep getPos[ (random 2001), (random 351)]; _prevStep = _step; }; _spot = [_step select 0,_step select 1,0]; diag_log format["_spot = %1", _spot]; }; _suitable = [_spot, 0, 300, 20, 0, 0.7, 0] call BIS_fnc_findSafePos; _list = nearestTerrainObjects [_suitable,["TREE","BUILDING","RUIN","ROCK","HOUSE"], _howBig,false]; diag_log format [">>> %1 %2 %3 ", _suitable,count _list, _spot]; }; _marker1 = createMarker ["Marker"+ str _suitable,_suitable]; _marker1 setMarkerType "hd_objective"; Then check the "_spot =" prints in the log Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 17:49:03 "_spot = [9666.13,3028.81,0]" 17:49:03 ">>> [9531.69,2972.07] 167 [9666.13,3028.81,0] " 17:49:03 ">>> [9455.88,3236.07] 38 [9666.13,3028.81,0] " 17:49:03 ">>> [9409.98,3141.88] 44 [9666.13,3028.81,0] " 17:49:03 ">>> [9784.95,2756.75] 103 [9666.13,3028.81,0] " 17:49:03 ">>> [9478.4,3219.99] 66 [9666.13,3028.81,0] " 17:49:03 ">>> [9432.54,3081.66] 112 [9666.13,3028.81,0] " 17:49:03 ">>> [9464.37,3226.52] 45 [9666.13,3028.81,0] " 17:49:03 ">>> [9672.66,2894.3] 131 [9666.13,3028.81,0] " 17:49:03 ">>> [9427.07,3079.41] 109 [9666.13,3028.81,0] " 17:49:03 ">>> [9411.67,3120.7] 75 [9666.13,3028.81,0] " 17:49:03 ">>> [9499.26,3231.2] 92 [9666.13,3028.81,0] " 17:49:03 ">>> [9650.26,2901.7] 129 [9666.13,3028.81,0] " 17:49:03 ">>> [9455.83,3235.39] 38 [9666.13,3028.81,0] " 17:49:04 ">>> [9454.94,3095.55] 126 [9666.13,3028.81,0] " 17:49:04 ">>> [9778.71,2757.8] 105 [9666.13,3028.81,0] " 17:49:04 ">>> [9486.06,3108.22] 126 [9666.13,3028.81,0] " Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 This is what it printed for me: 18:52:20 "_spot = [7819.88,3367.59,0]" 18:52:20 "_spot = [7012.37,4690.59,0]" 18:52:20 "_spot = [7960.8,4514.42,0]" 18:52:20 "_spot = [4829.26,7487.83,0]" 18:52:20 "_spot = [6527.62,6185.35,0]" 18:52:20 ">>> [7228,6987,0] 0 [6527.62,6185.35,0] " Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 Okey, I have to be missing something then. I am calling this script via debug console. like this : [100] spawn CHAB_fnc_findSpot; Each of my functions are listed in CfgFunctions.hpp. What do I do wrong? Share this post Link to post Share on other sites
gc8 977 Posted November 18, 2018 try placing your target guy in forest or something. Share this post Link to post Share on other sites
pierremgi 4862 Posted November 18, 2018 What is the aim of this code? In plain language. Share this post Link to post Share on other sites
JeyR 2 Posted November 18, 2018 Find a safe spot for a composition to spawn , randomly. Share this post Link to post Share on other sites
pierremgi 4862 Posted November 18, 2018 Just now, JeyR said: Find a safe spot for a composition to spawn , randomly. That's perhaps the problem. You need a too big safe pos (good luck on Tanoa!) and random is not efficient. Try a spiral, or some filter to avoid already checked areas. Share this post Link to post Share on other sites