KSP bug, ui_table precision lost

Run this code:
on init declare ui_table %table[4] (1, 1, 7200) %table[2] := 1908 message(%table[2]) end on on ui_control (%table) message(%table[2]) end on
When the script loads, the third column will be set to 1908 and be printed out. Now set any column except the third column to something else with your mouse. The third column will randomly get set to, and print out, 1907. This is a precision bug. If you add as many zeros as you can without overflow to the values, you'll see 190800000 -> 190799984. I don't know if this is ui_table specific.
And while I'm on this topic, there's a seconday reason why this is important. If you right click drag over a ui_table to draw a linear slope, $NI_CONTROL_PAR_IDX doesn't update. So if the last changed index of a table is significant in your code, you're going to have to keep a copy of the table data and manually loop through to check what's changed in the table callback each time. So if something is set to a precision-losing value like above during a table change operation, and then you change another value afterward, you're going to get that wrong index showing up as changed even though it wasn't, which messes everything up.
Comments
-
Yeah this is probably (but not 100% sure) a float to int then back to float precision issue. A pretty risky thing to fix since it can break existing libraries in unforeseen ways.
0
Categories
- All Categories
- 19 Welcome
- 1.5K Hangout
- 65 NI News
- 797 Tech Talks
- 4.1K Native Access
- 16.8K Komplete
- 2K Komplete General
- 4.4K Komplete Kontrol
- 5.8K Kontakt
- 1.6K Reaktor
- 386 Battery 4
- 854 Guitar Rig & FX
- 434 Massive X & Synths
- 1.3K Other Software & Hardware
- 5.9K Maschine
- 7.4K Traktor
- 7.4K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators