Jump to content
Sign in to follow this  
bigshotking

Undefined variable error BIS_fnc_selectRandom

Recommended Posts

private ["_powgrp", "_spawn", "_pow"];

if (isServer) then {
_powgrp = createGroup west;
_spawn = ["pow", "pow_1", "pow_2", "pow_3", "pow_4"] call BIS_fnc_selectRandom;
_pow = _powgrp createUnit ["US_Soldier_Officer_EP1", getMarkerPos _spawn, [], 0, "FORM"];
_pow setpos [(getpos _pow select 0),(getpos _pow select 1), 1];
_pow setRank "Private";
_pow allowFleeing 0;
_pow setDamage 0.5;
_pow setCaptive true;
removeAllWeapons _pow;
};

I keep getting a undefined variable error with the selectRandom line.

Here is a piece of the RPT file:

File C:\Users\user\Documents\ArmA 2 Other Profiles\player\mpmissions\mission.Takistan\objective.sqf, line 9
Error in expression <pow_1", "pow_2", "pow_3", "pow_4"] call BIS_fnc_selectRandom;

if (isServer) the>
 Error position: <BIS_fnc_selectRandom;

if (isServer) the>
 Error Undefined variable in expression: bis_fnc_selectrandom

I must have missed something, anyone know whats going on?

Share this post


Link to post
Share on other sites

Yes, Functions module is on the map

---------- Post added at 04:29 AM ---------- Previous post was at 03:07 AM ----------

Still not sure why the BIS_fnc_selectRandom does not work, but I decided to use this instead:

_hideout = floor(random 5);
_spawn = format ["spawn%1",_hideout];
_pow = _powgrp createUnit ["US_Soldier_Officer_EP1", getMarkerPos _spawn, [], 0, "FORM"];

Seems to work perfectly, but it's still strange why I'm getting that error...

Share this post


Link to post
Share on other sites

You can create your own function if the BIS one doesn't work:

MY_fnc_selectRandom = {
   _this select (floor random (count _this))
};

Then you can do:

_spawn = ["pow", "pow_1", "pow_2", "pow_3", "pow_4"] call MY_fnc_selectRandom; 

Share this post


Link to post
Share on other sites

You have to wait for the Functions Module to be ready, before using functions from it.

Or use Community Base Addons, it compiles the functions module before anything else is able to run.

Share this post


Link to post
Share on other sites

Yeah, that could sound like the problem, I was calling the script in the init, and thus it was being executed before getting in game.

Share this post


Link to post
Share on other sites

The function module initialization can be delayed considerably even seconds into the game, depending on script load.

You can wait on it with waitUntil, but I recommend using CBA, so the functions module is always ready.

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
Sign in to follow this  

×