Sign in to follow this  
Guest Skymed

Endless Loop

Recommended Posts

So here is my problem. An XML gauge with an equation with an end variable X that is dependent upon the previous state of the variable X, plus a constantly changing variable Y.The equation: X=X+Y Both X and Y are constantly being updated and the output is fed into the new X. All well and good. But the kicker is I need this updated as fast as possible (refresh at 18) but without getting into an endless loop. In other words, X=X+Y, if left untouched, becomes nothing more than an incremental counter as the gauge constantly says: (oldX)+Y = (new X) so the (new X) now equals the (old X), so it adds Y again and so on.What I need is a way in XML to look at the equation, see if anything has changed, increment/decrement only if changes are made and not to form an endless loop.If any of this makes any sense, I would love to see you guys solutions.Steve

Share this post


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

This is only logic, you can work out the syntax...Z!=Y if { X=X+Y }(Other code here, ending with: )Z=Y********The idea being that the last thing you do in any iteration is save the value of Y as Z so that, when you go get the current value of Y in the next iteration, you still have the old value to compare it to.Then test to see if the value is the same as last time... if so, skip your IF code. If it has changed, then update X.If you're testing to see that Y is non-zero then that's even easier... you don't even have to use Z at all.Scott

Share this post


Link to post
Share on other sites

Steve,I've been exhausted lately and just passed out for a few hours. I looked here again to check on a few topics and just now realized that this thread was started by *you*... So, I'll change gears here and look at this as if the answer couldn't possibly be as simple as I'd first thought.(Please excuse typos... I'm a big guy and usually use a Microsoft Natural keyboard that's huge and has a split in the middle but it failed to survive an encounter with Mt. Dew so I'm using a regular backup keyboard. This thing is TINY and I have trouble with the keys...)>So here is my problem. An XML gauge with an equation with an>end variable X that is dependent upon the previous state of>the variable X, plus a constantly changing variable Y.This says to me that old X always equals old X but Y changes.... therefore my first answer would work....>Both X and Y are constantly being updated and the output is>fed into the new X. This tells me that new X could be completely different from old X... meaning that this is possible:oldX = 5oldY = 1oldX+Y = 6newX = 326>What I need is a way in XML to look at the equation, see if>anything has changed, increment/decrement only if changes are>made and not to form an endless loop.Assuming that "anything" means that X could change as well as Y, we then need the following:************************************X != A if { A = X B = Y X = X + Y } els { Y != B if { A = X B = Y X = X + Y } }************************************It's a simple nested if approach that flows this way:1) Test to see if newX = oldX2) If not, update A and B to represent the current X and Y, then run the X + Y update and move on to other code.3) If newX = oldX, then test to see if newY = old Y4) If not, update A and B to represent the current X and Y, then run the X + Y update and move on to other code.5) If oldY = newY, skip to the rest of the code and leave everything as is.This still strikes me as something that you'd be helping me with, not the other way around. Am I misunderstanding what you need or have you been in the egg nog again buddy? (grin)Scott / Vorlin

Share this post


Link to post
Share on other sites

Hey Scottyeah its me :-)Complete brain f@rt with this one, as I'm having logic difficulties. Must be getting too old. Will have a look at the code you provided and work through the logic. I appreciate the help.Steve

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