Sign in to follow this  
spokes2112

Decimal multiplication in XML

Recommended Posts

In the following code, each click on a gauge button increases the CourseSet variable by one. It will count up to 359, then reset to zero on the next click. These values are degrees on the compass. On the last line, I want to convert the degree value into radian for further calculations. When the degrees are multiplied by .01745, a zero value always results. If the code below is incorrect, how do you multiply decimal values in XML?(L:CourseSet, degrees) 1 + (>L:CourseSet, degrees) ;(L:CourseSet, degrees) 359 > if{ 0 (>L:CourseSet, degrees) } ;(L:CourseSet, degrees) .01745 * (>L:CourseRadian, radian)I've also substituted this code on the last line above to see if XML would do the conversion for me, but no luck.(L:CourseSet, degrees) (>L:CourseRadian, radian)Thanks,Glenn

Share this post


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

Hi Glenn,I've never been able to figure out which conversions work for L:Vars and which don't.So I'll always use "number" and "bool" for my variables.And this:(L:CourseSet,number) 0.01745 * (>L:CourseRadian,number)will definitely work.It could also be the missing 0 before the decimal point.Rob

Share this post


Link to post
Share on other sites

Hi,May be this works:(L:CourseSet,degrees) dgrd (>L:CourseRadian,radian)or use number:(L:CourseSet,number) dgrd (>L:CourseRadian,number)Hope it helps,Jan"Beatus Ille Procul Negotiis"

Share this post


Link to post
Share on other sites

Hi,>>>(L:CourseSet, degrees) (>L:CourseRadian, radian)This won't work.Rather is a direct conversion, just change the unit:(L:CourseSet, radians)Tom

Share this post


Link to post
Share on other sites

This works:180 (>L:CourseSet, degrees)(L:CourseSet, radians) will equal 3.14 'ish'pi (>L:CourseSet, radians)(L:CourseSet, degrees) dnor will equal 180This will also work,180 (>L:CourseSet, enum)(L:CourseSet, enum) dgrd = 3.14pi (>L:CourseSet, enum)(L:CourseSet, enum) rddg = 180--Jon

Share this post


Link to post
Share on other sites

Thanks, good answers. I went with adding a zero in front of the decimal. Apparently, XML does not recognize decimals unless they are surrounded by digits. I

Share this post


Link to post
Share on other sites

Hi Glen,You could use this construction: (M:Event) 'LeftSingle' scmp ! if{ (G:Var1) ++ (>G:Var1) (G:Var1) 1 == if{ (P:ABSOLUTE TIME,seconds) (>G:Var2) } (P:ABSOLUTE TIME,seconds) (G:Var2) - 1 < if{ "code that increments your var by 1" } els{ "code that increments your var by 10" } } (M:Event) 'LeftRelease' scmp ! if{ 0 (>G:Var1) }So:Normally Var1 is 0.When the mouse is depressed and held, the 'LeftSingle' section is continuously executed.The first "click" (Var1 = 1) sets Var2 to current time.Keeping it depressed will continuously increment Var1, so Var2 is set only once ("start-time").So the first second the "incr by 1" code is executed.When the "current-time - start-time > 1 sec", the "incr by 10" code is executed.Releasing the mouse sets Var1 back to zero, to initialise it for a next "click-and-hold" event.This construction is never affected by "acceleration" problem you see in many gauges, and makes it very easy to use another "hold-time" than 1 sec. Just replace the "1" by another period.Cheers, Rob Barendregt

Share this post


Link to post
Share on other sites

That solution looks good. I'll give it a try tomorrow. Thanks,Glenn

Share this post


Link to post
Share on other sites

I tried the code. It works in this fashion: When I single-click the mouse, the cursor rotates in 10-degrees increments. When I keep the mouse button down, the cursor then rotates continously in 1-degree increments. But, upon releasing the button, the cursor jumps 10-degrees one final time before stopping.I think I

Share this post


Link to post
Share on other sites

Hi Glenn,I'd appreciate if you could show me where my example is wrong :-)Because I can't explain the behaviour you describe ..Rob

Share this post


Link to post
Share on other sites

Hi Rob,I took a glance to your code, just by curiosity :-)At first thought it has something to do with (P:Absolute time) being negative, but then realized it's ok...so I second your post.Regards,Tom

Share this post


Link to post
Share on other sites

If you guys see nothing wrong, then I may have followed your instructions incorrectly although it looks okay to me. I can

Share this post


Link to post
Share on other sites

Hi Glenn,Try to replace:(P:ABSOLUTE TIME,seconds) (G:Var2) - 1 " as ">") in an XML expression.Rob

Share this post


Link to post
Share on other sites

Rob,The code was written with the "and, l, t"; however, these were changed by this b/b to the "less than" symbol when I posted. I'm not sure why that happened because I have the Message format box checked.Glenn

Share this post


Link to post
Share on other sites

Hi,I had a look and may be there are some } too much and what does a seperate ; ?Also, using repeat="Yes" can give some problem when choosing between 1 and 10.After editing:(M:Event) 'LeftSingle' scmp ! if{ (G:Var1) ++ (>G:Var1) (G:Var1) 1 == if{ (P:ABSOLUTE TIME,seconds) (>G:Var2) } (P:ABSOLUTE TIME,seconds) (G:Var2) - 1 < if{ (L:CourseSet, degrees) 1 + (>L:CourseSet, degrees) (L:CourseSet, degrees) 359 > if{ 0 (>L:CourseSet,degrees) } (L:CourseSet, degrees) 0.01745 * (>L:CourseRadian, radian) } els{ (L:CourseSet, degrees) 10 + (>L:CourseSet, degrees) (L:CourseSet, degrees) 359 > if{ 0 (>L:CourseSet,degrees) } (L:CourseSet, degrees) 0.01745 * (>L:CourseRadian, radian) } } (M:Event) 'LeftRelease' scmp ! if{ 0 (>G:Var1) } (L:CourseRadian, radians) (A:Plane heading degrees gyro,radians) - (>L:CourseCursor, radians) (L:CourseCursor, radians)Not tested!, Hope it helps,Jan"Beatus Ille Procul Negotiis"

Share this post


Link to post
Share on other sites

This code now increases the cursor in steps of one degree per click. When the mouse is held down, it moves continously but only one-degree per step, not 10. That is what was happening originally.Maybe I need four buttons, two that increase/decrease in steps of 10; two that increase/decrease in steps of 1. Maybe simpler is better in this case. Simmers love buttons anyway. I think I can handle the four button code.Glenn

Share this post


Link to post
Share on other sites

Hi Glenn,I suggest you use this code. It works fine:(M:Event) 'LeftSingle' scmp ! if{ (G:Var1) ++ (>G:Var1) (G:Var1) 1 == if{ (P:ABSOLUTE TIME,seconds) (>G:Var2) } (P:ABSOLUTE TIME,seconds) (G:Var2) - 1 < if{ (L:CourseSet, degrees) ++ dnor (>L:CourseSet, degrees) } els{ (L:CourseSet, degrees) 10 + dnor (>L:CourseSet, degrees) } } (M:Event) 'LeftRelease' scmp ! if{ 0 (>G:Var1) } Things to add:"++" is the same as "1 +" (and -- is otherwise)"dnor" makes the resulting number be converted to degrees directly.This saves the "(L:CourseSet, degrees) 359 > if{ 0 >L:CourseSet,degrees) }" sentence (which is incorrect when incrementing by 10) and makes the code more clear."(L:CourseSet, degrees) 0.01745 * (>L:CourseRadian, radian)"Is not needed at all. Let FS make the conversion for you, which btw will be more precise than the factor you are using. use always "amphersand l t ;" instead of (L:CourseSet, radians) (A:plane heading degrees gyro,radians) - Regards,TomPS: Do you have a mousewheel? If so, have you tried scrolling the wheel over the click zone? I use this method to make ample increments.

Share this post


Link to post
Share on other sites

Hi,This is the working code of a heading-bug in a ND.(Rotation around a compass rose)I used Rob's and Tom's click-code and added something and tested it and it works as expected:I don't use G:Var'sDecrease:(M:Event) 'LeftSingle' scmp ! if{ (L:heading,number) ++ (>L:heading,number) (L:heading,number) 1 == if{ (P:ABSOLUTE TIME,seconds) (>L:heading timer,number) } (P:ABSOLUTE TIME,seconds) (L:heading timer,number) - 1 < if{ (L:CourseSet,degrees) -- dnor (>L:CourseSet,degrees) (L:CourseSet,degrees) (>K:HEADING_BUG_SET) } els{ (L:CourseSet,degrees) 10 - dnor (>L:CourseSet,degrees) (L:CourseSet,degrees) (>K:HEADING_BUG_SET) } } (M:Event) 'LeftRelease' scmp ! if{ 0 (>L:heading,number) } Increase:(M:Event) 'LeftSingle' scmp ! if{ (L:heading,number) ++ (>L:heading,number) (L:heading,number) 1 == if{ (P:ABSOLUTE TIME,seconds) (>L:heading timer,number) } (P:ABSOLUTE TIME,seconds) (L:heading timer,number) - 1 < if{ (L:CourseSet,degrees) ++ dnor (>L:CourseSet,degrees) (L:CourseSet,degrees) (>K:HEADING_BUG_SET) } els{ (L:CourseSet,degrees) 10 + dnor (>L:CourseSet,degrees) (L:CourseSet,degrees) (>K:HEADING_BUG_SET) } } (M:Event) 'LeftRelease' scmp ! if{ 0 (>L:heading,number) } (A:Autopilot heading lock dir,radians) (A:Plane heading degrees gyro,radians) - You can use a bitmap instead of this vector of course.So one click gives one degree rotation and pressing longer gives 10.May be this is what you want.(Same should be possible for alt, vs(very small increments!), obs, speed etc.)Hope it helps,Jan"Beatus Ille Procul Negotiis"

Share this post


Link to post
Share on other sites

>>PS: Do you have a mousewheel? If so, have you tried scrolling>the wheel over the click zone? I use this method to make ample>increments.>As Tom suggested, don't want to forget about the wheel. You can even take that a step farther by adding wheel up and down event handlers for your click area code. This would allow for more precise conrol of the results when the wheel is used. If you find you're reusing click code for multiple events, you could even stick Jan's goodies in some macros and just call them when you need 'em.Like Tom, I tend to use the mousewheel frequently as well. I guess it just "feels" more like turning a knob on the panel. Granted, there may be those who don't have or use scollers, the standard button click events (as in the examples above) will still be there for them.

Share this post


Link to post
Share on other sites

Thanks, I'll dig through this code later. I want to use code that I understand and that usually takes a bit of study and head scratching on my part. I can see that vectors will become a priority soon. Is speed their advantage over using bitmaps?Thanks for your help,Glenn

Share this post


Link to post
Share on other sites

Regarding the use of the ampersand: I do use that for all my code. However, when I copy my code to this b/b, all ampersands structures are changed to the

Share this post


Link to post
Share on other sites

I just discovered the problem and it was me.Tom's code works as he said. The problem was in the way I was testing the gauge.I had been testing it while FS was in pause. The cursor would moved using the mouse so I assumed everything was normal. But the cursor would only move in the 1-degree steps as I had been posting.I unpause FS to see if gauge worked when aircraft was flying. That is when I discovered the cursor will rotate like it is supposed to, even in 10-degree increments.I don't know why this happens, but I guess calculation are different when paused and not.Thanks everyone for the assistance. Glenn

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