Archived

This topic is now archived and is closed to further replies.

Herbie63

how to use max / min in xml to limit the value of a var...

Recommended Posts

Hi all,surely it is a simple thing, but i cannot get my head around this.How does one limit the value of a variable using the max / min function?For instance i want to limit L:my variable, number to 10.Right now i use this kind of code but it is getting awkward if one has multiple variables in one statement. (crowded with if's)(L:My Variable, number) 10 lt; if{ (L:My Variable, number) ++ (>L:My Variable, number) }.I have been staring at the MS throttle code for quite some time now, they use 1 max 0 min in their statement:(M:Y) (*Get Y*) 30 - (*skip top runof*) 103 / (*divide by running height*) 0 max 1 min (*into [0-1]*) 1 - /-/ (*from bttom to top*) 1 (A:Throttle lower limit,part) s0 - * l0 + (*apply lower limit*) 16384.0 * (*KEY_THROTTLE1_SET requires 16k*)(>K:THROTTLE2_SET)Tried to use that in my custom spoiler lever code (with appropriate values) but no joy... My spoiler code works using multiple if's, but i am keen to learn new techniques and keep code as clean as possible.grtWillem.

Share this post


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

Willem, (L:MyVar, number) 1 + 10 min (>L:MyVar, number) means L:Myvar will be the comparison minimum of the two numbers, 10 & (L:MyVar, number) 1 + ... meaning it will never go above 10.Just reverse it for max(L:MyVar, number) 1 - 0 max (>L:MyVar, number)... It will never go below zero..Now if you have a fluctuating variable ( like in the spoiler dealing with the handle position ) invovled in your equation and you need a range -256 thru 256 for instance..(L:MyVar, number) (L:FluctuatingVar, number) + -256 max 256 min (>L:MyVar, number) will do the trick and keep it in range.Roman

Share this post


Link to post
Share on other sites

For whatever perverted reason, min and max function precisely the opposite of what their names imply...A reasonable person would assume that "min" means minimum, i.e., a lower limit. Likewise, one would think that "max" in fact means maximum!In the FS XML world however, rules of logic appear to have been formulated by the Mad Hatter in Wonderland... :-xxrotflmao

Share this post


Link to post
Share on other sites

Ahh,now that makes sense....NOT.But thanks for the answer guys, this is of great help!Should have known it works opposite of what could be expected. After all it is XML and on top of that, it is for FS so all reason was supposed to be thrown overboard for some time now...lolTHANKS!grWillem.

Share this post


Link to post
Share on other sites

That always /boggled me until I thought about what it's really doing, and so after adjusting my thinking instead of fighting it, it makes sense:)MAX returns the maximum value of the two stack entries, just as the name implies.-20 0 MAX returns 0 because it is the larger of the two values.likewise 20 0 MAX returns 20 because it is the larger of the two values.min returns the minimum:20 0 min returns zero because it is the smaller of the two values. Likewise 60 50 min returns 50 because it is the smaller of the two values.Makes more sense now?--Jon

Share this post


Link to post
Share on other sites

Aha, if you look at it that way, it actually could make sense yes...Still, i need some time to adjust to this...Thanks!grWillem

Share this post


Link to post
Share on other sites

Hehehe...only at first sight. Once you get used to the rpn syntax it's logical (at least to me).I read something like '10 20 max' like"having 10 and 20 in mind and using the max of it"For me C++ is much more strage than XML, but I guess it's just a question of what one is more familiar to...br,Herbert

Share this post


Link to post
Share on other sites