Jump to content
Sign in to follow this  
Guest Vorlin

Loops, If's, Case and other coding stuff...

Recommended Posts

TC2,Nice try! :-), good for you. There's no other way to master XML code than doing an "endless loop" of tests :D""So I am stuck with lots of "if{" statements to do achore that, with a simple variable array call, could have beenone short line. Oh well! Back to coding if{ statements :)""Why is that? You only need a few if{ statements for simple arrays (see my former example in this thread)Now, as you're a die hard tester :-), take a look at this macro@1(1) @1(2) @1(3) @1(4) @1(5) @1(6) @1(7) @1(8)@1(9) @1(10) @1(11) @1(12) @1(13) @1(14) @1(15) @1(16)@1(17) @1(18) @1(19) @1(20) @1(21) @1(22) @1(23) @1(24)@1(25) @1(26) @1(27) @1(28) @1(29) @1(30) @1(31) @1(32)@1(33) @1(34) @1(35) @1(36) @1(37) @1(38) @1(39) @1(40)It can't be said that there is a lot of code here. But with this core macro you can add, retrieve, delete, insert, invert, values within an array of 40 LVars. Maybe you'd want to figure out a way on how to use it in a real example...Regards,TomPD: I'm not a Master, just a tough tester *:-*

Share this post


Link to post
Share on other sites
Guest Tomcattwo

Thanks Tom. Based on one of your other clever suggestions for loops, I tried to use one in a macro, however, it isn't providing the expected results - it isn't looping. The gauge its used in appears, so there are no syntax errors that the parser can't understand, but the macro isn't performing. Note that my channel indices are not contiguous, but case allows them to become numerically contiguous. Here's the code: %((L:field,enum) 10 / int 1 + (L:mempgnr,enum) 1 - 5 * + sp2)%(20 sp1) %{loop} %(l1)%{case}%{:0}%{:1}%(0 (>L:ch211,enum))%{:2}%((L:ch211,enum) (>L:ch221,enum))%{:3}%((L:ch221,enum) (>L:ch231,enum))%{:4}%((L:ch231,enum) (>L:ch241,enum))%{:5}%((L:ch241,enum) (>L:ch251,enum))%{:6}%((L:ch251,enum) (>L:ch212,enum))%{:7}%((L:ch212,enum) (>L:ch222,enum))%{:8}%((L:ch222,enum) (>L:ch232,enum))%{:9}%((L:ch232,enum) (>L:ch242,enum))%{:10}%((L:ch242,enum) (>L:ch252,enum))%{:11}%((L:ch252,enum) (>L:ch213,enum))%{:12}%((L:ch213,enum) (>L:ch223,enum))%{:13}%((L:ch223,enum) (>L:ch233,enum))%{:14}%((L:ch233,enum) (>L:ch243,enum))%{:15}%((L:ch243,enum) (>L:ch253,enum))%{:16}%((L:ch253,enum) (>L:ch214,enum))%{:17}%((L:ch214,enum) (>L:ch224,enum))%{:18}%((L:ch224,enum) (>L:ch234,enum))%{:19}%((L:ch234,enum) (>L:ch244,enum))%{:20}%((L:ch244,enum) (>L:ch254,enum)) %(l1 -- s1 l2 >)%{next}%{end}(L:field,enum) carries a value of 10,20,30,40 or 50 and a single value is already present when the macro is called.(L:mempgnr,enum) carries a value of 1,2,3 or 4 and a single value is already present when the macro is called.The values of (L:field,enum) and (L:mempgnr,enum) determine the stop index (which carries a value between 1 and 20, inclusive). For example, if (L:field,enum) = 30 and (L:mempgnr,enum)=1, then the value stored in register 2 should be:Calculations in RPN:30 10 / => 3 3 int => 33 1 + => 41 1 - => 00 5 * => 04 0 + => 44 => sp2The loop should start by executing case 20, then 19, 18, ...4, and then stop.The call is @insert and no arguments are passed.The call results in no evidence that the macro is working - no channel values change when the call is made. I can't read the registers, so I've no idea where the loop is stopping.I also tried it by making the {case} part into a separate macro and calling it from within the "Insert" macro with an argument of (l1). That didn't work either - same symptoms.Any idea what might be causing this to not loop? or other suggestions?R/ and many thanks for all your help so far,TC2(Tom Stevenson, Montclair Virginia USA)

Share this post


Link to post
Share on other sites

Tom,I think the correct syntax should be:{loop}value{case}{:1}...{:20}{end}conditional{next}No need to use {:0} if you won't have a value here; works different from stack's "case" structure.And I assume you are calling the macro within a tag?- like @insert - because if called from inside a it won't work. Tom

Share this post


Link to post
Share on other sites
Guest Tomcattwo

Tom, as usual, you are correct. Despite the syntax change, the loop failed to work properly when called from a click statement. So I went back to the drawing board, and, using macros and a slightly different arrangement of my array (inspired by your 40 item single array), made it work! Here's the code for those interested:(L:field,enum) 10 / int (L:mempgnr,enum) 1 - 5 * + (>L:chnnbr,enum) (L:chnnbr,enum)@1 20 < if{ (L:ch244,enum) (>L:ch254,enum) }@1 19 < if{ (L:ch234,enum) (>L:ch244,enum) }@1 18 < if{ (L:ch224,enum) (>L:ch234,enum) }@1 17 < if{ (L:ch214,enum) (>L:ch224,enum) }@1 16 < if{ (L:ch253,enum) (>L:ch214,enum) }@1 15 < if{ (L:ch243,enum) (>L:ch253,enum) }@1 14 < if{ (L:ch233,enum) (>L:ch243,enum) }@1 13 < if{ (L:ch223,enum) (>L:ch233,enum) }@1 12 < if{ (L:ch213,enum) (>L:ch223,enum) }@1 11 < if{ (L:ch252,enum) (>L:ch213,enum) }@1 10 < if{ (L:ch242,enum) (>L:ch252,enum) }@1 9 < if{ (L:ch232,enum) (>L:ch242,enum) }@1 8 < if{ (L:ch222,enum) (>L:ch232,enum) }@1 7 < if{ (L:ch212,enum) (>L:ch222,enum) }@1 6 < if{ (L:ch251,enum) (>L:ch212,enum) }@1 5 < if{ (L:ch241,enum) (>L:ch251,enum) }@1 4 < if{ (L:ch231,enum) (>L:ch241,enum) }@1 3 < if{ (L:ch221,enum) (>L:ch231,enum) }@1 2 < if{ (L:ch211,enum) (>L:ch221,enum) }@1 1 < if{ 0 (>L:ch211,enum) }@delete(@channum) (L:scratch,enum) (>L:ch254,enum) 0 (>L:insflg,bool)The calls are very simple (from click statements):If I want to insert a 0 as a value into a channel in the array of memory channels, shifting all channel values down 1 space, I set a flag, then I store the value of channel 254 (the 20th channel in the array) in a scratch variable in case I need to undo it. Then I call the insert macro using macro @channum as the argument. Channum sets the index value to stop at (start at in the case of a @delete call) the active channel (which is known already when the call is made). So the full call is:1 (>L:insflg,bool) (L:ch254,enum) (>L:scratch,enum) @delete(@channum)If I want to undo the insert, all I have to do is call:@undoins and voila! everything is restored back to where it was before the insert call!Delete and UndoDel work in the same fashion.Tom, thanks a million for all the help on this! On to coding the next subsection!Many warm regards,TC2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...