Jump to content
mrchooch

Error "0 Elements provided, 3 expected"

Recommended Posts

_display = _params select 0;
_ctrlTreeVehicles = _display displayCtrl IDC_RSCDISPLAYGARAGE_TREEVEHICLES;
_ctrlComboSkin = _display displayCtrl IDC_RSCDISPLAYGARAGE_COMBOSKIN;
_ctrlCheckMoveIn = _display displayCtrl IDC_RSCDISPLAYGARAGE_CHECKMOVEIN;
_curSel = tvCurSel _ctrlTreeVehicles;
_curSelSkin = lbCurSel _ctrlComboSkin;
_className = _ctrlTreeVehicles tvData _curSel;

//--- Calculate spawn position
switch(true) do {
	case (_className isKindOf "LandVehicle"): {_marker = "LandSpawn"} ;
	case (_className isKindOf "Helicopter"): {_marker = "HeliSpawn"};
	case (_className isKindOf "Plane"): {_marker = "PlaneSpawn"};
	case (_className isKindOf "Ship"): {_marker = "ShipSpawn"};
	default {_marker = "LandSpawn"};
};

_marker = "GroundSpawn"; //<-- Whoops, ignore this, left over from testing
_pos = getMarkerPos _marker;

//--- Check for nearby entities
{deleteVehicle _x;} forEach nearestObjects [ _pos, [ "LandVehicle", "Helicopter","Plane", "Ship" ], 10 ];

//--- Create vehicle
_vehicle = createVehicle [ _className, _pos, [], 0, "CAN_COLLIDE" ];
_vehicle setDir markerDir _marker;

Here's the offending part of the code.

When I run it, I get the error in the title.

 

Interesting to note:

  • Removing the whole switch(true) do part and manually setting _marker to something makes it work fine, but then I cant choose the marker based on vehicle type
  • If I replace the "_pos" in nearestObjects and createVehicle with what _pos directly is (getMarkerPos <MarkerName>) makes it work fine, but then I cant choose the marker based on vehicle type

 

Please help, its 6 am and ive been trying to fix for hours. Havent slept yet

Share this post


Link to post
Share on other sites

You have this line:

_

marker = "GroundSpawn";

Which invalidates your switch options by overwriting the value after the switch.  If a "GroundSpawn" marker doesn't exist, it also fails to produce a valid _pos value which gives you that error.

Share this post


Link to post
Share on other sites

You have this line:

_

marker = "GroundSpawn";

Which invalidates your switch options by overwriting the value after the switch.  If a "GroundSpawn" marker doesn't exist, it also fails to produce a valid _pos value which gives you that error.

My mistake, thats just there from me testing, I forgot to remove it. Regularly, that wouldnt be there and I would get the aforementioned error

Share this post


Link to post
Share on other sites

What line was giving you that error?

I should have mentioned that.

{deleteVehicle _x;} forEach nearestObjects [ _pos, [ "LandVehicle", "Helicopter","Plane", "Ship" ], 10 ];

But specifically the nearestObjects part. If i omit that line then createVehicle on the next line throws the same error

Share this post


Link to post
Share on other sites

I guess this line isnt working:

_pos = getMarkerPos _marker;

you should test if _pos contains a 3D position array. u could do that with:

systemChat format ["%1", _pos];

Share this post


Link to post
Share on other sites

 

I guess this line isnt working:

_pos = getMarkerPos _marker;

you should test if _pos contains a 3D position array. u could do that with:

systemChat format ["%1", _pos];

 

It just prints the word "array"

Share this post


Link to post
Share on other sites
systemChat format ["%1", (count _pos)];

try this

Share this post


Link to post
Share on other sites
systemChat format ["%1", (count _pos)];

try this

 

 

It prints "scalar"

Share this post


Link to post
Share on other sites

hmm, the first line should print somethinkg like this [2435.11, 8325.22,0]

the second line should print: 3

Are u sure that u have existing markers with the marker names u r using in the switch?

Share this post


Link to post
Share on other sites

try this please:

if (_marker in allMapMarkers) then {systemChat "Marker found";}
else {systemChat "marker not existent";};

Share this post


Link to post
Share on other sites

My mistake, thats just there from me testing, I forgot to remove it. Regularly, that wouldnt be there and I would get the aforementioned error

 

when you have it there does it work?

 

I think the problem is that your not defining _marker variable before the switch.

  • Like 1

Share this post


Link to post
Share on other sites

hmm, the first line should print somethinkg like this [2435.11, 8325.22,0]

the second line should print: 3

Are u sure that u have existing markers with the marker names u r using in the switch?

 

Yep, all the markers are there.

 

Are there any alternate ways to achieve what im trying to do? I just want to see what type of vehicle is chosen and then spawn it at the marker that corresponds to the class of vehicle

Share this post


Link to post
Share on other sites

Ahh, scalar is because you're setting _marker inside the switch so when it's referenced outside that code block it's unknown.

 

This will work:

_marker = switch(true) do {
	case (_className isKindOf "LandVehicle"): {"LandSpawn"};
	case (_className isKindOf "Helicopter"): {"HeliSpawn"};
	case (_className isKindOf "Plane"): {"PlaneSpawn"};
	case (_className isKindOf "Ship"): {"ShipSpawn"};
	default {"LandSpawn"};
};

_pos = getMarkerPos _marker;

Share this post


Link to post
Share on other sites

when you have it there does it work?

 

I think the problem is that your not defining _marker variable before the switch.

that should be the reason...

Share this post


Link to post
Share on other sites

Ahh, scalar is because you're setting _marker inside the switch so when it's referenced outside that code block it's unknown.

 

Makes sense, how can I fix this?

Share this post


Link to post
Share on other sites

Makes sense, how can I fix this?

_marker ="";

just before ur switch...

 

EDIT: :ph34r:  :D

Share this post


Link to post
Share on other sites

define the _marker variable: 


_marker = ""; // define the variable

//--- Calculate spawn position
switch(true) do {
	case (_className isKindOf "LandVehicle"): {_marker = "LandSpawn"} ;
	case (_className isKindOf "Helicopter"): {_marker = "HeliSpawn"};
	case (_className isKindOf "Plane"): {_marker = "PlaneSpawn"};
	case (_className isKindOf "Ship"): {_marker = "ShipSpawn"};
	default {_marker = "LandSpawn"};
};


;)

Share this post


Link to post
Share on other sites
_marker ="";

just before ur switch...

 

EDIT: :ph34r:  :D

 

 

 

define the _marker variable: 


_marker = ""; // define the variable

//--- Calculate spawn position
switch(true) do {
	case (_className isKindOf "LandVehicle"): {_marker = "LandSpawn"} ;
	case (_className isKindOf "Helicopter"): {_marker = "HeliSpawn"};
	case (_className isKindOf "Plane"): {_marker = "PlaneSpawn"};
	case (_className isKindOf "Ship"): {_marker = "ShipSpawn"};
	default {_marker = "LandSpawn"};
};


;)

 

I've been pulling my hair out for the past 8 hours and it was that simple...

 

Thanks guys, I appreciate it

 

I still have a problem or two that are related to this script but ill make a seperate post for those

Share this post


Link to post
Share on other sites

And here is the related rule u need to follow:

 

If u define (first use) a variable inside a code block (could be while/if then/switch/waitUntil ...) then the variable is deleted if ur script leaves that code block.

If u need the variable and its content after that code block then u need to define the variable before.

Share this post


Link to post
Share on other sites

Makes sense, how can I fix this?

 

I added the code to my previous post.

Share this post


Link to post
Share on other sites

And here is the related rule u need to follow:

 

If u define (first use) a variable inside a code block (could be while/if then/switch/waitUntil ...) then the variable is deleted if ur script leaves that code block.

If u need the variable and its content after that code block then u need to define the variable before.

 

Yeah, ive been using Python a lot before this so theres a few tiny things I always forget... such as those damn semicolons

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

×