tophe 69 Posted July 5, 2008 Hello. I have this bit of code in my script: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _rNumber = floor(random 11); if (_rNumber == 0) then (husLogic setPos (getPos hus1)); if (_rNumber == 1) then (husLogic setPos (getPos hus2)); if (_rNumber == 2) then (husLogic setPos (getPos hus3)); if (_rNumber == 3) then (husLogic setPos (getPos hus4)); if (_rNumber == 4) then (husLogic setPos (getPos hus5)); if (_rNumber == 5) then (husLogic setPos (getPos hus6)); if (_rNumber == 6) then (husLogic setPos (getPos hus7)); if (_rNumber == 7) then (husLogic setPos (getPos hus8)); if (_rNumber == 8) then (husLogic setPos (getPos hus9)); if (_rNumber == 9) then (husLogic setPos (getPos hus10)); if (_rNumber == 10) then (husLogic setPos (getPos hus11)); if (_rNumber == 11) then (husLogic setPos (getPos hus12)); The code will will get a random number and depending on what it is execute the command... In this case a gameLogic that is to be moved to another gameLogics position. But it always picks the last one... It always ends up at hus12. If I take the last row out, it will end up at the position of hus11. How can I fix this? I guess my syntax is messed up. Thx for any help! Share this post Link to post Share on other sites
sickboy 13 Posted July 5, 2008 Hello.I have this bit of code in my script: You have used ( and ) Â where you should've used { and }.e.g: if (bla) then ( doBla ); should be: if (bla) then { doBla }; Secondary; I would exchange then with exitWith, as no more of the code needs to be executed anymore, after the _rNumber was found. However, I would recommend: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _rNumber = ceil (random 12); husLogic setPos (getPos (call compile format["hus%1", _rNumber])); Or: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _ar = [hus1, hus2, hus3, hus4, hus5, hus6, hus7, hus8, hus9, hus10, hus11, hus12]; _rNumber = floor (count _ar); husLogic setPos (getPos (_ar select _rNumber)); You could also use switch case, however, I would recommend one of the above. Share this post Link to post Share on other sites
tophe 69 Posted July 6, 2008 Thank you sickboy! I just realized the brackets ! Your code snippet was just what I had in mind when I started. Very nice code indeed! Clean and small. Thank you so much for your time and help! // Tophe of OOPS Share this post Link to post Share on other sites