Author Topic: [Solved] I don't understand why my token conversion is not working  (Read 1431 times)

Shenron

  • Newbie
  • *
  • Posts: 16
Hi,

I have this simple command :
Code: [Select]
Write [Blue] '{DEC:EliteAPI.FSSDiscoveryScan.Progress}' to log

The output is
Code: [Select]
0,772317
But this command :
Code: [Select]
Set decimal [~percent] value to the converted value of {DEC:EliteAPI.FSSDiscoveryScan.Progress}
Write [Blue] '{DEC:~percent}' to log

Give me this result :
Code: [Select]
772317
What did i missed ? i can't figure it out
« Last Edit: June 20, 2022, 03:39:11 AM by Shenron »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: I don't understand why my token conversion is not working
« Reply #1 on: June 18, 2022, 04:47:12 PM »
As mentioned in the documentation, there are specific variants of the decimal-related tokens that output in an invariant-culture format (I.E. with a period as the decimal separator)


Internally, there are no actual periods or commas in use when storing the value in memory, but as soon as the value is converted to text, as is done by the tokens, the culture settings of your system (Windows) determine which character is used.

VoiceAttack is standardized, like many applications and programming languages, on using a period as a decimal separator for international compatibility when converting text to numeric values.
So when you use the regular "{DEC:}" token, and the output uses a comma as the decimal separator, that will be interpreted as a thousands separator (E.G. as in "1,000,000" for one million), and the leading zero will be dropped as it has no place in an integer number.


If you use "{DECINV:}" instead, the text value will not use your system culture settings, but rather a culture not tied to any specific country or region (the invariant culture) which will use a period as the decimal separator, and commas as the thousands separators.


All of that is moot (irrelevant) in this case, however, as you don't need a conversion at all; the value is already stored in memory as a number.

Instead of using a token, input the actual variable name into the "Another Variable" field.

Shenron

  • Newbie
  • *
  • Posts: 16
Re: I don't understand why my token conversion is not working
« Reply #2 on: June 20, 2022, 03:38:40 AM »
Hi Pfeil,

Thank you for the explanation.
I was also thinking about the culture but shame on me to not have tested copying the value as-is.

This way it's fully working
Code: [Select]
Set decimal [~percent] value to the value of [{EliteAPI.FSSDiscoveryScan.Progress}]
Set decimal [~percent] to [~percent] times 100,00000 (round to 0 decimal places)

sorry to not have tested this before

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: I don't understand why my token conversion is not working
« Reply #3 on: June 20, 2022, 09:29:50 AM »
Code: [Select]
Set decimal [~percent] value to the value of [{EliteAPI.FSSDiscoveryScan.Progress}]

The curly braces are part of the token syntax, not the variable name. This happens to work "accidentally" because the token parser will remove any curly braces that don't form part of a valid token (and aren't escaped explicitly).