Thanks for you kind comment.
I recall a saying – If it’s not broken don’t try and fix it! Bare that in mind.
Since I’m on a steep learning curve trying to get in to PRT and the coding side, I decided to analyse the code you posted as an exercise. If this is beyond or distracting to what your doing, feel free to ignore. Just sharing.
The code here is just main code but the .itf file has a lot more comments in it, why I changed and/or added things.
I’ve learned a lot doing this and wouldn’t have done it if it wasn’t for your post and well laid out request/spec.
In analyzing I have, replaced/altered/created some variables with stock/new, replaced original ‘if’ block and added a value guard, error message and logic control to the ‘K’ variable if invalid.
Additionally, it made me figure out a couple of technique when checking that code changers give same outcome’s. These such as creating alternate, by a numbered index, variable’s to calculate a kind of before and after type scenario and by subtracting one from the other it should result in zero if there the same
Also by having a indicator panel with original and a new file with the original copied in it, as changes are made you can see if expected result are obtained. Also have a original in price window. A plan is better than no plan.
Not possibly rocket science or ground breaking but, kept me focused on the task for a while. As always do your own testing.
All the best.
// include dynamic variable
// 'K' decimal/integer, default 500
ONCE AFR = totalPrice
// Input Guard - Limits 'K' input range +(1 to 2000) @ 1 d.p.
validK = round(max(min(K,2000), 1),1)
// Calculate CONSTANT
CONSTANT = validK/10000
// Input gaurd error code - if 'K' exceeds set limit's give warning!
if K < 1 or K > 2000 then
drawtext("ERROR! ~ K = #K# Out of Range (1-2000)",0,8,Dialog,Bold,15)Anchor(bottom)coloured("RED")
else
// else run the number cruncher - calculate new AFR
Smooth = AFR + (totalPrice - AFR) * SQRT(CONSTANT * 2)
Velo = Velo + CONSTANT * (totalPrice - AFR)
AFR = Smooth + Velo
// Set colour value's for 'AFR' line, 'green' velo > 0, 'red' velo <= 0
if Velo > 0 then
g = 255
r = 0
else
g=0
r=255
endif
endif
RETURN AFR coloured(r,g,0) // new AFR value set to required colour's