Jump to content

Recommended Posts

The script I'm working on calls for random sqf selection. I found this, here, and I want to make sure I understand the function. Please advise if my comments to the script are correct.

_script = [1,3] call BIS_fnc_randomInt;  //defines a range for cases, actually says 1-3 or 1, 2, 3. Selects one randomly.
switch (_script) do { // -- I think it says if "_script" is defined, do
case 1 : { [] execVM "1.sqf"; };  //put script names here
case 2 : { [] execVM "2.sqf"; };
case 3 : { [] execVM "3.sqf"; };
};

SwitchDo
So I could,

EMERGENCY = [1,3] call BIS_fnc_randomInt;
switch (EMERGENCY) do {
case 1 : { [] execVM "searchZONE.sqf"; };
case 2: { [] execVM "searchZONE2.sqf"; };
case 3 : { [] execVM "noEMERG.sqf"; };
};

Can I increase the probability of a script by using it for multiple cases? Or would I use something like selectRandomWeighted?

Share this post


Link to post
Share on other sites

you could:

_scripts = ["searchZONE.sqf", "searchZONE2.sqf", "noEMERG.sqf"];

_selected = selectRandom _scripts;

[] execVM _selected;

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
5 minutes ago, wogz187 said:

Can I increase the probability of a script by using it for multiple cases? Or would I use something like selectRandomWeighted?

 

Yes use that.

 

You can also do:


 

_scriptFile = selectRandom ["searchZONE.sqf","searchZONE2.sqf"];

execVM _scriptFile;

 

 

Edit: sarogahtyp beat me 🙂

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@gc8, @sarogahtyp,

LOL!

Answered twice and simplified before I even finished editing the topic. Lemme try this out and we'll wrap this thread up. 😄

Share this post


Link to post
Share on other sites

Or with selectRandomWeighted:


 

_scriptFile = ["searchZONE.sqf","searchZONE2.sqf"] selectRandomWeighted [0.1, 0.5];

execVM _scriptFile;

 

  • Like 4

Share this post


Link to post
Share on other sites

@gc8,

You don't want the radio call to fail with "noEMERG.sqf". LOL!

Thanks again, man. You know where I'm going with this.

  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites

Arma 3. How to select a script and random.

 

 

On 7/11/2019 at 1:18 AM, sarogahtyp said:

you could:


_scripts = ["searchZONE.sqf", "searchZONE2.sqf", "noEMERG.sqf"];

_selected = selectRandom _scripts;

[] execVM _selected;

 

 

I put this here so I can find it again easily!  Fabulous!

 

 

Share this post


Link to post
Share on other sites

@Joe98,

A year later and this can be simplified,

_selected = selectRandom ["searchZONE.sqf", "searchZONE2.sqf", "noEMERG.sqf"];

[] execVM _selected;

But I wouldn't do it like that anymore.

Instead of a bunch of .sqf files-- I'd just use a single configurable function.

_selected = selectRandom [1,2,3];
[_selected] spawn you_fnc_searchZone;

In dealing with randomness I've found it's a good idea to record what is currently active for other scripts to reference.

missionNameSpace setVariable ["mission_type", _selected];


Have fun!

  • Like 3

Share this post


Link to post
Share on other sites

depends always on OPs knowledge at the time he is asking.

 

a year ago u didn't know 'bout function library I guess. So at this time it was the easiest way to get a working solution for you.

also there is nothing wrong with seperating things in different files. the real advantage comes with using precompiled functions...

  • Like 3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×