Rommel 2 Posted June 18, 2008 Now compared to my last thread on OFPEC, for something less trivial (hopefully...) <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_index"]; _index = switch (startSide) do { case WEST: {_index = 0; hint format ["%1", _index]}; case EAST: {_index = 1; hint format ["%1", _index]}; }; hint format ["%1", _index]; _Index Returns <NULL> in the last hint, however it returns the assigned number within the Switch scope. I was aware that the private at the beginning would fix this issue by making the variable applicable to all scopes? Rommz, EDIT: Whilst I know that an If command works just as well (and actually works), I am still interested in an answer for this. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _index = switch (startSide) do { case WEST: {_index = 0; hint format ["%1", _index]}; case EAST: {_index = 1; hint format ["%1", _index]}; }; if (startSide == WEST) then { _index = 3; }; _Index returns 3; Share this post Link to post Share on other sites
xeno 231 Posted June 18, 2008 This is the way to go : <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_index"]; startSide = west; _index = ( Â Â switch (startSide) do { Â Â Â Â case WEST: {0}; Â Â Â Â case EAST: {1}; Â Â } ); hint format ["%1", _index]; The following will work too: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_index"]; startSide = west; _index = (if (startSide == west) then {0} else {1}); hint format ["%1", _index]; Xeno Share this post Link to post Share on other sites
Rommel 2 Posted June 18, 2008 Haha thanks mate, I just edited above post to say I knew that an IF would work, but wasn't sure about why the Switch wouldnt. Thanks . Share this post Link to post Share on other sites
General Barron 0 Posted June 18, 2008 Haha thanks mate, I just edited above post to say I knew that an IF would work, but wasn't sure about why the Switch wouldnt.Thanks . The switch is working correctly. The switch returns the results of the very last command processed. In your example, the last command processed is: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format ["%1", _index] Obviously, the 'hint' command doesn't return anything, which is why _index is being set to null after the switch. Share this post Link to post Share on other sites
Rommel 2 Posted June 19, 2008 Yeh thanks mate, Spooner just made me aware of this, I keep forgetting how many people check these forums (both BIS and OFPEC) per hour, I think i'll just keep it localized to one of em unless it gets really hairy. Thanks all. Problems solved. Share this post Link to post Share on other sites