Results 1 to 3 of 3

Thread: Need help with my IF statements.

  1. #1
    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&#40;random 11&#41;;

    if &#40;_rNumber == 0&#41; then &#40;husLogic setPos &#40;getPos hus1&#41;&#41;;
    if &#40;_rNumber == 1&#41; then &#40;husLogic setPos &#40;getPos hus2&#41;&#41;;
    if &#40;_rNumber == 2&#41; then &#40;husLogic setPos &#40;getPos hus3&#41;&#41;;
    if &#40;_rNumber == 3&#41; then &#40;husLogic setPos &#40;getPos hus4&#41;&#41;;
    if &#40;_rNumber == 4&#41; then &#40;husLogic setPos &#40;getPos hus5&#41;&#41;;
    if &#40;_rNumber == 5&#41; then &#40;husLogic setPos &#40;getPos hus6&#41;&#41;;
    if &#40;_rNumber == 6&#41; then &#40;husLogic setPos &#40;getPos hus7&#41;&#41;;
    if &#40;_rNumber == 7&#41; then &#40;husLogic setPos &#40;getPos hus8&#41;&#41;;
    if &#40;_rNumber == 8&#41; then &#40;husLogic setPos &#40;getPos hus9&#41;&#41;;
    if &#40;_rNumber == 9&#41; then &#40;husLogic setPos &#40;getPos hus10&#41;&#41;;
    if &#40;_rNumber == 10&#41; then &#40;husLogic setPos &#40;getPos hus11&#41;&#41;;
    if &#40;_rNumber == 11&#41; then &#40;husLogic setPos &#40;getPos hus12&#41;&#41;;
    [/QUOTE]

    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&#33;

  2. #2
    Quote Originally Posted by (Olle Stolpe @ July 05 2008,23:42)
    Hello.
    I have this bit of code in my script:
    You have used ( and ) ***where you should&#39;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 &#40;random 12&#41;;
    husLogic setPos &#40;getPos &#40;call compile format&#91;&#34;hus%1&#34;, _rNumber&#93;&#41;&#41;;
    [/QUOTE]
    Or: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    _ar = &#91;hus1, hus2, hus3, hus4, hus5, hus6, hus7, hus8, hus9, hus10, hus11, hus12&#93;;
    _rNumber = floor &#40;count _ar&#41;;
    husLogic setPos &#40;getPos &#40;_ar select _rNumber&#41;&#41;;
    [/QUOTE]

    You could also use switch case, however, I would recommend one of the above.



    A.C.E. Advanced Combat Environment

    Dev-Heaven.net Free Project Hosting | A2 Community Issue Tracker Help BIS, Help yourself!

  3. #3
    First Sergeant Tophe's Avatar
    Join Date
    Jun 4 2004
    Location
    Örebro/Sweden
    Posts
    925
    Author of the Thread
    Thank you sickboy&#33;
    I just realized the brackets &#33;

    Your code snippet was just what I had in mind when I started. Very nice code indeed&#33; Clean and small.

    Thank you so much for your time and help&#33;

    // Tophe of OOPS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •