Sign in to follow this  
nickpike

Use of S0 and L0 on different lines.

Recommended Posts

Hi, whilst mooching through this very imformative forum, I noticed in some XML code that s0 and l0 registers were used on different lines in the same element block.I always thought they could only be used and paired on the same line of code.The code snippet was,(L:Condition, bool) (L:Condition2, bool) ands0l0 if{ a bunch of trig }Can sombody please confirm this. Presumably, the paired registers can only be used in the same element block.Also, would performance be enhanced if, say, s0 and l0 were used in one element, and in another element use s1 and l1 to stop the first register being overwritten?cheers,nick

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Nick,That was my snippet, so I might as well throw in my $0.02.>I always thought they could only be used and paired on the same line of code.No, The same registers can be used not only in different constructs within the element, but also by multiple elements as long as there is a containing element.>Presumably, the paired registers can only be used in the same element block.Again, not a limitation as long as the multiple elements are children of another element.--Jon

Share this post


Link to post
Share on other sites

Thanks Jon, you learn something new everyday. I shall now go and put this little gem into practise,cheers,nick

Share this post


Link to post
Share on other sites

Actually, a further thought. If using multiple element blocks sandwiched by a parent element block, is it bad practise to use the same s0 l0 pair in each element block. Would it be better to use s0 l0 in the first element, s1 l1 in the second, etc. I'm thinking this might give FS more to do if using the same suffix number?cheers,nick

Share this post


Link to post
Share on other sites

Nick,The 50 registers (s0-s49) are valid for the ENTIRE gauge. You can save a value (ie s0) in any part of a gauge -in , ,,, etc- and retrieve it in another (as l0).Any time you save to "s0" you're actually overwriting its content, so two things to consider here:1-It does no harm to use the same register as may times as you wish2-As a consequence of this, you have to be carefull when using the same register in multiple single/nested macros, because you may end up losing data "unawarely".TomNote: remember "s" doesn't remove the saved value from the stack. You must use "sp" instead, and this is also especially important when dealing with complex macros.

Share this post


Link to post
Share on other sites

Many thanks. Very useful. Sorry to bother you further, but could you explain,>Note: remember "s" doesn't remove the saved value from the stack. You must use "sp" instead, and this is also especially important when dealing with complex macros.I take it S0 remains in the register until overwritten. What is the significance of 'popping' the value. Why do this, and if 'popped' off the stack how would , say, l0 get the value of sp0?cheers,nick

Share this post


Link to post
Share on other sites

>I take it S0 remains in the register until overwritten. What>is the significance of 'popping' the value. Why do this, and>if 'popped' off the stack how would , say, l0 get the value of>sp0?>"sp0" first saves the value to register 0 then removes ("pops") it from the stack so it would not interfere with any further operation.But it can still be recalled with "l0".As an example, just take a look at my "rolling numbers" macro:(A:Indicated Altitude, feet) sp0 l0 int 10 @2 pow % 10 @2 1 - @1 1 - - 0 max pow / intI use this to call the macro: @AltDigit(4,4) s1 9980 >=l1 100 % 80 - 20 / * @AltDigit(1,5) +Now, if ever I use (A:Indicated Altitude, feet) s0 instead of (A:Indicated Altitude, feet) sp0 The result will be quite different! CheersTom

Share this post


Link to post
Share on other sites

Many thanks, now fully understood. You always write clearly and explain things very well, I always understand your explanations. And thanks for having the patience to answer my questions,cheers,nick

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