Jump to content
Sign in to follow this  
Ub3rObama

Error 0 elements provided, 3 expected, driving me nuts!

Recommended Posts

So I can't get rid of this bloody error, even though it doesn't actually effect anything it still spams like crazy. I've tried everything I can think of, such as adding an if statement which checks if the array exists/the size of the array but whatever is going on keeps getting past the if statements.

Error:

a = 0; for "a" from 0 to 20 do{
_veh = createVehicle [_vehiclesArray select ran>
 Error position: <createVehicle [_vehiclesArray select ran>
 Error 0 elements provided, 3 expected

Script:

if (!isServer) exitWith {};
private ["_pos","_veh","_weapon","_vehiclesArray","_weaponsArray","_magsArray","_townsArray","_car"];

_vehiclesArray = [
"ATV_US_EP1",
"HMMWV_M1035_DES_EP1",
"Ikarus_TK_CIV_EP1",
"LandRover_CZ_EP1",
"2S6M_Tunguska",
"MAZ_543_SCUD_TK_EP1",
"Offroad_SPG9_TK_GUE_EP1",
"SUV_UN_EP1",
"Ural_UN_EP1",
"VolhaLimo_TK_CIV_EP1"
];

_weaponsArray = [
"m107_TWS_EP1",
"M24_des_EP1",
"AKS_74_GOSHAWK",
"M4A3_RCO_GL_EP1",
"SCAR_L_STD_EGLM_TWS",
"M60A4_EP1",
"MG36_camo"
];

_magsArray = [
"10Rnd_127x99_m107",
"5Rnd_762x51_M24",
"30Rnd_545x39_AK",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"100Rnd_762x51_M240",
"100Rnd_556x45_BetaCMag"
];

_secondaryMagsArray = [
"",
"",
"",
"1Rnd_HE_M203",
"1Rnd_HE_M203",
"",
""
];

_townsArray = [
"Kamenyy",
"Strelka",
"Airfield"
];

x = 0; for "x" from 0 to count _townsArray do{
a = 0; for "a" from 0 to 20 do{
		_veh = createVehicle [_vehiclesArray select random count _vehiclesArray,[_townsArray select x] call SHK_pos,[], 0, "FLYING"];
			_veh setDir random 360;
			_veh setFuel (100 - random 80) * 0.01;
			_veh setVehicleArmor (100 - random 50) * 0.01;
			clearWeaponCargoGlobal _veh;
			clearMagazineCargoGlobal _veh;
			_weapon = random count _weaponsArray;
			_veh addWeaponCargoGlobal [_weaponsArray select _weapon, 1];
			_veh addMagazineCargoGlobal [_magsArray select _weapon, (random 6) + 1];
			if(!(_secondaryMagsArray select _weapon == "")) then{
				_veh addMagazineCargoGlobal [_secondaryMagsArray select _weapon, (random 5) + 1];
			};
		sleep 0.1;
};
};

Share this post


Link to post
Share on other sites

I suspect it's _veh = createVehicle [_vehiclesArray select random count _vehiclesArray,[_townsArray select x] call SHK_pos,[], 0, "FLYING"];

try replacing [_townsArray select x] call SHK_pos with a simple gamelogic to see if the error goes away.

create a game logic name it gl

_veh = createVehicle [_vehiclesArray select random count _vehiclesArray,getpos gl,[], 0, "FLYING"];

I usually find this Error 0 elements provided, 3 expected relates to position

Share this post


Link to post
Share on other sites

Dam, that is the problem. I really need a way to get a random position in a marker area, and SHK pos seemed to be perfect, but it must be spitting out something that messes with it. Sigh. I'm gonna have to keep looking or come up with something else.

Share this post


Link to post
Share on other sites

Taking a shot in the dark here, maybe it will throw same errors idk...

_pos = [b][_townsArray select x] call SHK_pos[/b]
_veh = createVehicle [_vehiclesArray select random count _vehiclesArray,_pos,[], 0, "FLYING"];

or

_veh = createVehicle [_vehiclesArray select random count _vehiclesArray,position _pos,[], 0, "FLYING"];

Share this post


Link to post
Share on other sites

Tried the first one already, thats where I also added in if statements to check if it was an array and if it had something in it, Ill try the other now.

Got this error, which is just confusing.

Error in expression <rray select random count _vehiclesArray,position _pos,[], 0, "FLYING"];
_veh set>
 Error position: <position _pos,[], 0, "FLYING"];
_veh set>
 Error position: Type Array, expected Object,Location

But it makes me think that SHK_pos is returning an array instead of position? Even though I thought they were the same thing.

Share this post


Link to post
Share on other sites

If you have an undefined variable in an if condition, it will skip the condition and show no errors, which can drive you mad if you don't know about it.

If you notice an if statement is always skipped (both the then and the else parts), make sure the variables inside the conditions are defined (as in !(isNil "_varName") ). If they are undefined, assuming they are typed correctly, you have a problem elsewhere that assigns a nil value to them...

Share this post


Link to post
Share on other sites

GUYS GUYS I WORKED IT OUT, THE ANSWER TO ALL MY PROBLEMS EVERY SINGLE BLOODY ONE!

Its this line right here, that I have used multiple times:

_vehiclesArray select random count _vehiclesArray

Looks good right? Wrong. Arrays start at 0, count doesn't. So whats been happening is when it gone to use a random index, its actually been pulling an index thats 1 to high which has been causing errors.

Now its:

_vehiclesArray select random (count _vehiclesArray - 1)

I did this to all the others and no errors at all! And weapons are spawning in every car like it should!

Bloody amazing how these tiny things can cause such a pain in the ass.

Share this post


Link to post
Share on other sites

LOL. I've just logged in and was about to say that. You do need to be careful with count array.

But do be cautious using select random in this way. Random won't be supplying integers here. That's not a problem, select will round them, but random floor is much better.

You should run some debug to check that it's choosing the first and last element of your array as often as it should.

See discussion here, particularly post 6 onwards.

http://forums.bistudio.com/showthread.php?138741-round-random-unexpected-behaviour-round-floor-expected-behaviour!

Share this post


Link to post
Share on other sites
Tried the first one already, thats where I also added in if statements to check if it was an array and if it had something in it, Ill try the other now.

Got this error, which is just confusing.

Error in expression <rray select random count _vehiclesArray,position _pos,[], 0, "FLYING"];
_veh set>
 Error position: <position _pos,[], 0, "FLYING"];
_veh set>
 Error position: Type Array, expected Object,Location

But it makes me think that SHK_pos is returning an array instead of position? Even though I thought they were the same thing.

Just thought I'd throw this in here:

_pos is already a position, so there's no need to define the position again (since you used "position _pos"), using "_pos" is enough.

Share this post


Link to post
Share on other sites

Yes, use select (floor (random _count)). Your method has a chance to return a negative index!

Share this post


Link to post
Share on other sites

I can't seem to get anything back when using _pos = [_townsArray select x] call SHK_pos

even using a simple test reveals nothing

pos= "Strelka" call SHK_pos;

hint str pos;

result nothing

and I'm using in this in an init.sqf

call compile preprocessfile "SHK_pos\shk_pos_init.sqf";

Share this post


Link to post
Share on other sites
Yes, use select (floor (random _count)). Your method has a chance to return a negative index!

And as the OP found using random round, which is what select random effectively is, can easily choose an index that is outside the top of the array.

Share this post


Link to post
Share on other sites
I can't seem to get anything back when using _pos = [_townsArray select x] call SHK_pos

even using a simple test reveals nothing

pos= "Strelka" call SHK_pos;

hint str pos;

result nothing

and I'm using in this in an init.sqf

call compile preprocessfile "SHK_pos\shk_pos_init.sqf";

You either need to give a marker name, or a position to SHK_pos:

 Marker Based Selection
   Required Parameters:
     0 String   Area marker's name.

   Optional Parameters:
     1 Boolean           Allow water positions? Default is false.
     2 Array or String   One or multiple blacklist area markers which are excluded from the main marker area.

 Position Based Selection
   Required Parameters:
     0 Object or Position  Anchor point from where the relative position is calculated from.
     1 Array or Number     Distance from anchor.

   Optional Parameters:
     2 Array of Number     Direction from anchor. Default is random between 0 and 360.
     3 Boolean             Water position allowed? Default is false.
                             false    Allow water positions.
                             true     Find closest land. Search outwards 360 degrees (20 degree steps) and 20m steps.
     4 Array               Road positions.
                             0  Number  Road position forcing. Default is 0.
                                  0    Do not search for road positions.
                                  1    Find closest road position. Return the generated random position if none found.
                                  2    Find closest road position. Return empty array if none found.
                             1  Number   Road search range. Default is 200m.

 Usage:
   Preprocess the file in init.sqf:
     call compile preprocessfile "SHK_pos\shk_pos_init.sqf";

   Actually getting the position:
     pos = [parameters] call SHK_pos;

Looks like I missed one, you can give a marker, object, or position. If you use object or position, I believe you must give distance from said object/position

Edited by panther42

Share this post


Link to post
Share on other sites

Yea I tried that as well, but still nothing not even an error.

Share this post


Link to post
Share on other sites
Yes, use select (floor (random _count)). Your method has a chance to return a negative index!

floor only rounds down correct? Which means it would never get the highest index. Round would be better yeah?

Upon thinking about that, I realize how floor is so much better and that was quite a dumb comment.

Edited by Ub3rObama

Share this post


Link to post
Share on other sites

Well considering floor only rounds down, if you have an index of [0,1,2] you simply use (floor(random 3)); since it always rounds down.

Share this post


Link to post
Share on other sites
What happens if random 3 = 3? or is that impossible?

Yes, random 3 will never choose 3.

Share this post


Link to post
Share on other sites

Random will never choose exactly the edge of the bound as far as I'm aware (even if it can, there is probably a higher chance for your computer to randomly catch fire), so 0 < random 3 < 3. You can get numbers very close to 0 or 3, but that is OK as it will get "floored" to 0 or 2.

As for getting "nothing", I'd look for what the function is doing, and assuming the function isn't bugged, check if what you're using as a parameter is actually a legal parameter for the function. In any case, you're on the right track for isolating the problem, as you can see you have minimized the problem to 2 lines of code, meaning you'll probably fix it soon :)

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  

×