Author Topic: How do I test for plus/minus 1 degree  (Read 1067 times)

Boston

  • Newbie
  • *
  • Posts: 18
How do I test for plus/minus 1 degree
« on: February 02, 2023, 04:06:03 PM »
Code: [Select]
Else If : ([decFreq] Equals [decNewFreq] AND [{MSFSAgent.PlaneState.Plane_Latitude}] Is Greater Than [(decLat - 1)] AND [{MSFSAgent.PlaneState.Plane_Latitude}] Is Less Than [(decLat + 1)] AND [{MSFSAgent.PlaneState.Plane_Longitude}] Is Greater Than [(decLong - 1)] AND [{MSFSAgent.PlaneState.Plane_Longitude}] Is Less Than [(decLong+1)])
     

[decFreq] Equals [decNewFreq] works

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How do I test for plus/minus 1 degree
« Reply #1 on: February 02, 2023, 04:11:46 PM »
Have you read the documentation?

Arbitrarily putting brackets everywhere isn't going to work.

Boston

  • Newbie
  • *
  • Posts: 18
Re: How do I test for plus/minus 1 degree
« Reply #2 on: February 02, 2023, 09:24:25 PM »
I have read the PDF Pfeil. It is not as clear for me as it is for you. There are many things I do well... this is not one of them yet. I understand variables vs tokens and I know the inside is done first. But the difference between [{( is somewhat black magic to me. I write to the log ALL THE TIME as you suggested in other posts I have read. It is a great tip. I probably have more lines of "Write a Value to the Event Log" than code. What you are witnessing is the end result of hours/days of iterations and frustration.

I am truly sorry if you are frustrated by newbie questions. Please know the very last thing on my mind when posting this question was if the person replying would be dismissive. I was in a state of mind crushed by my ineptitude.

You have been EXTREMELY helpful in my efforts to read text files. I thank you for that. No need to reply.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How do I test for plus/minus 1 degree
« Reply #3 on: February 03, 2023, 04:52:18 AM »
The part that is working can be left out for the moment, so that leaves you with
Code: [Select]
Else If :
(
[{MSFSAgent.PlaneState.Plane_Latitude}] Is Greater Than [(decLat - 1)] AND
[{MSFSAgent.PlaneState.Plane_Latitude}] Is Less Than [(decLat + 1)] AND
[{MSFSAgent.PlaneState.Plane_Longitude}] Is Greater Than [(decLong - 1)] AND
[{MSFSAgent.PlaneState.Plane_Longitude}] Is Less Than [(decLong+1)]
)
The curly braces around your variable names are unnecessary. Luckily they will be removed automatically (specifically because of this type of scenario where they are added unnecessarily), which should allow the actual variable names to be interpreted correctly.

However, what cannot work is taking a field intended for a variable name, putting parentheses in there, and attempting to perform mathematical operations.
Is it suggested anywhere in the documentation you have read, that that is possible? Do you feel that it is logical that a field labeled "Another Variable" would accept such input?


Other than that, the logic you're attempting to express seems sound.

Only the "Text" tab of condition and loop actions accepts tokens in any of its fields (which is why the topmost field is labeled "Variable Name / Token"), so you can potentially use the "{EXP:}" token in that tab to perform mathematical operations.
However, especially with decimal values I would recommend using the mathematical options within the variable datatype's action (I.E. the "Set a Decimal Value" action, in this case) instead.

E.G.
Code: [Select]
Set decimal [decLatMinimum] value to the value of [decLat]
Set decimal [decLatMinimum] to [decLatMinimum] minus 1
and so on.

Boston

  • Newbie
  • *
  • Posts: 18
Re: How do I test for plus/minus 1 degree
« Reply #4 on: February 03, 2023, 01:46:30 PM »
Well, I feel stupid. I was close but use Convert decimal instead.

Code: [Select]
Write [Blue] 'decLat is {DEC:decLat}' to log
Convert decimal [DEC:decLat] to decimal [DEC:decLatMin]
Write [Blue] 'decLatMin is {DEC:decLatMin}' to log
Convert decimal [DEC:decLat] to decimal [DEC:decLatMax]
Write [Blue] 'decLatMax is {DEC:decLatMax}' to log
Set decimal [decLatMin] to [decLatMin] minus 1
Set decimal [decLatMax] to [decLatMax] plus 1

Set makes more sense.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: How do I test for plus/minus 1 degree
« Reply #5 on: February 03, 2023, 01:55:50 PM »
The "Convert a Variable Value" action can be used for this, though as there will be no actual conversion it's perhaps not the first choice.

However, in the set of actions you have there, by adding "DEC:" as part of the variable names, you're retrieving the value of a variable that likely has not been set, and storing that value in a variable you're not using further along in the command.

The "Set a" actions prevent that specific mistake by rejecting variable name input that contains colons; clearly that safeguard has not yet been extended to the "Convert a Variable Value" action. I'll pass that along to the developer.