Jump to content
Sign in to follow this  
IndeedPete

Switch Do Problem

Recommended Posts

Hi all,

i want to simulate a mortar attack around a base and wrote a small script, wich unfortunately doesn't work. But i can't see where the mistake is. Maybe someone can help?

Here's the script:

_base = _this select 0;
_baseX = getPos _base select 0;
_baseY = getPos _base select 1;

while {artyDublin} do {
_posX = _baseX + 60 -(random 20);
_negX = _baseX - 60 +(random 20);
_posY = _baseY + 60 -(random 20);
_negY = _baseY - 60 +(random 20);
_x = round(random 3);

switch (_x) do {
	case 0: {_targetX = _posX; _targetY = _posY;};
	case 1: {_targetX = _posX; _targetY = _negY;};
	case 2: {_targetX = _negX; _targetY = _posY;};
	case 3: {_targetX = _negX; _targetY = _negY;};
	default {hint "No Target"};
};

det = "SH_125_HE" createVehicle [_targetX,_targetY,0];
sleep 3;
};

Thanks in advance!

Edit: Here's the last .rpt entry:

det = "SH_125_HE" createVehicle [_targetX,_targetY,0];
sle>
 Error position: <createVehicle [_targetX,_targetY,0];
sle>
 Error Type Any, expected Number
File C:\Documents and Settings\Administrator\My Documents\ArmA 2 Other Profiles\IndeedPete\missions\ORS_08_Dublin_A.Chernarus\scripts\artyDublin.sqf, line 21

Edited by IndeedPete

Share this post


Link to post
Share on other sites

No idea really... Only possible thing I can think of is that getPos _base select X; should be written as getPos (_base select X);

Other than that, which I'm not even sure is a syntax error, I can't see anything wrong.

Share this post


Link to post
Share on other sites

Yes, that's exactly my problem!^^ I've read the BIKI about "switch-do" 5 times and i can't see anything wrong...

Share this post


Link to post
Share on other sites

_targetX and _targetY are probably local variables of the switch block and undefined out of it. Try private["_targetX","_targetY"] before the switch block or a simple _targetX = 0 to expand the scope.

Share this post


Link to post
Share on other sites

Oh, right. Good find. I completely forgot to check the scope of the variables. T_D is perfectly correct.

Share this post


Link to post
Share on other sites

Yup, that works! Thank you T_D!

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  

×