FartParty 10 Posted December 13, 2013 I need a script that will count randomly from 1 to 7, i'm not sure where to start only just getting into scripting, it's very difficult can anyone point me in the right direction Share this post Link to post Share on other sites
TeTeT 1523 Posted December 13, 2013 How does one count randomly? Do you mean having an array [1,2,3,4,5,6,7] and then shuffling that? That would be best accomplished via CBA: _shuffled = [[1, 2, 3, 4, 5, 6, 7]] call CBA_fnc_shuffle; See https://dev-heaven.net/docs/cba/files/arrays/fnc_shuffle-sqf.html Share this post Link to post Share on other sites
moricky 211 Posted December 13, 2013 Or you can use existing function BIS_fnc_arrayShuffle, without need to install any addon: [1, 2, 3] call BIS_fnc_arrayShuffle; More about functions Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 Why allocate an array when you could use this? x=floor(random 7)+1; will return 1-7 Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 Why allocate an array when you could use this? x=floor(random 7)+1; will return 1-7 That will return a random number between 1 and 7, but it seems like the OP wanted to have a loop iterate 7 times and each time choose a unique number between 1 and 7. In that case he would need an array. Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 I need a script that will count randomly from 1 to 7 I don't see where the loop comes into play. Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 I don't see where the loop comes into play. From the first post I need a script that will count randomly from 1 to 7 Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 (edited) Okay whatever you say. _count = 0; while {_count < 6} do { x=floor(random 7)+1; //Do something with random number _count = _count + 1; }; Edited December 13, 2013 by Johnson11B2P for to increment the counter Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 Okay whatever you say. _count = 0; while {_count < 6} do { x=floor(random 7)+1; //Do something with random number }; But from what the OP says, it looks like he wants each number to be unique. Your example can choose the same number more than once. For example: 1, 4, 5, 6, 2, 1, 6 If he wanted to have each number selected exactly once you would need an array. [1, 2, 3, 4, 5, 6, 7] Then using the array shuffle function you get the numbers in a random order, [4, 2, 3, 7, 5, 1, 7] The difference is that in the second example each number is unique. Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 _numbers = [1,2,3,4,5,6,7]; while{_count < 6} do { _numbers call BIS_fnc_arrayShuffle; _num = _numbers call BIS_fnc_arrayPop; _count = _count + 1; }; Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 _numbers = [1,2,3,4,5,6,7]; while{_count < 6} do { _numbers call BIS_fnc_arrayShuffle; _num = _numbers call BIS_fnc_arrayPop; _count = _count + 1; }; Although it would only be necessary to shuffle the array once. Since after you shuffle it, all of the elements are in a random order. Also, BIS_fnc_arrayShuffle returns the new sorted array, so you would have to store it. _numbers = _numbers call BIS_fnc_arrayShuffle. { // Do something with _x (the random number) } foreach ([1, 2, 3, 4, 5, 6, 7] call BIS_fnc_arrayShuffle) This would be a little bit more efficient. Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 Way more efficient. Share this post Link to post Share on other sites
FartParty 10 Posted December 13, 2013 thanks, this is very helpful, but i'm not sure i understand how to use this information i have 7 triggers on the map, and i want to activate them all in a random order they are activated by whatever this is called "trigger1 = true" Share this post Link to post Share on other sites
Johnson11B2P 3 Posted December 13, 2013 { _x = true; } foreach ([trigger1,trigger2, trigger3, trigger4, trigger5, trigger6, trigger7] call BIS_fnc_arrayShuffle) Also change your condition code to trigger1 == true Check out this website for further information. http://community.bistudio.com/wiki/a_%3D%3D_b Share this post Link to post Share on other sites
iceman77 18 Posted December 14, 2013 To check boolean (true/false) of a variable, use the variables name. ie; if (trigger1) then {hint "It's true";} else {hint "It's false";}; //example 1 if (!trigger1) then {hint "It's false";} else {hint "It's true";};//example 2 Share this post Link to post Share on other sites
FartParty 10 Posted December 14, 2013 okay i used that code, but it's not doing anything How do i use it to activate the triggers? I want each trigger to be a script. it will activate trigger1, which in turn will activate a script (being a gamemode [e.g. team deathmatch/capture the flag]) it will wait until the gamemode has concluded, tally a winner, and call the next gamemode, repeat, until all 7 have been played a.k.a. warzone from the killzone series Share this post Link to post Share on other sites
iceman77 18 Posted December 14, 2013 okay i used that code, but it's not doing anything ... I want each trigger to be a script. it will activate trigger1, which in turn will activate a script (being a gamemode [e.g. team deathmatch/capture the flag]) it will wait until the gamemode has concluded, tally a winner, and call the next gamemode, repeat, until all 7 have been played a.k.a. warzone from the killzone series Ahh yes, that was a simple explanation on how to check if a variable has been set to true or false. The variable can be anything you like. And you're asking how to make one mission, containing a huge nest of different game modes? LOL, I wont touch this one! But good luck getting the ball rolling on that. Share this post Link to post Share on other sites
FartParty 10 Posted December 14, 2013 ah thanks anyway my goal is just too advanced for my ability i'm afraid Share this post Link to post Share on other sites
iceman77 18 Posted December 14, 2013 ah thanks anywaymy goal is just too advanced for my ability i'm afraid Start smaller imo. I recommend reading Mr.Murray's editing guide from front to back (experimenting along the way with the examples provided) and then moving on to Mikie's scripting tutorials. Youtube and google are also very helpful. Share this post Link to post Share on other sites