Corroder Grandmaster Cheater Reputation: 17
Joined: 10 Apr 2015 Posts: 619

Posted: Sat Feb 24, 2018 8:04 pm Post subject: 


Before goes to answer your questions, first we talk is about you mean with "divide 32 rule". Correct me if I misunderstood.
On my understanding, 32 rule is :
a fraction (23 bits), an exponent (8 bits), and a sign (1 bit) from a number. so that the number is approximately equal to (in Lua) :
Code:  math.ldexp(fraction, exponent  127) * (sign == 1 and 1 or 1) 
and then packs the generated values into 32 bits.
So, a better way to pack numbers is the IEEE754 singleprecision floatingpoint format in Lua
But, a certain function in the math library in Lua say :
Code:  The frexp function breaks down the floatingpoint value (v) into a mantissa (m) and an exponent (n), such that the absolute value of m is greater than or equal to 0.5 and less than 1.0, and v = m * 2^n.
Note that math.ldexp is the inverse operation.

However, the mantissa returned by this function is not an integer.
So, let we go to discuss your question one by one (make attention, I'm not answer your questions, it's more like a discuss).
1. how to convert a float value in my ct to a variable ?
What is a variable ?. A Variable is an element, feature, or factor that is liable to vary or change. In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Typically, a program consists of instruction s that tell the computer what to do and data that the program uses when it is running.
So in other way a variables or variables is part of data.
As same as data, a variable contain : value, type an given name.
In your case : we know your value is float, so float type is number and then to store that float value as a variable, we need give it a name.
Code:  example :
myVar = 2 / 7.5 > result is 0.26666666666667 is a floating value
myVar = variable name
myVar type = math operation = float = number

So, in your case to 'CONVERT' a float value to a variable, just do :
Code: 
your_variable_name = your_float_value 
in CT, to give name as a variable, doubleclick description field and change description with yours.
2.how to put that float value inside a cecaption (following the divide 32 rule) ?
This 'cecaption', need more references about this mean. Is this 'cecaption' put inside a CE Trainer or where ?.
Anyhow, because this said 'caption', then this mean type of text or string and because float value type is number, then we need convert float number to string.
Code:  Example using CE 6.7 which has adapted Lua 5.3 (should be give different result if use Lua 5.1 / Lua 5.2)
x = 2 / 7.5
print(x) > result : 0.26666668057442
print(type(x)) > result : number
x1 = tostring(x)
print(x1) > result : 0.26666668057442
print(type(x1)) > result : string
 next we can use : cecaption.Caption = tostring(your float value) 
But, I'm not sure x = 2 / 7.5 result is a float value. It more as a integer value. Note : in Lua all number should be adapted as integer value.
To get accurate precision number from result of 2 / 7.5 should be use IEEE754 singleprecision floatingpoint format as mentioned above.
3.how to have the float variable divide by 32 before writing/reading ?
I am skip this. Need more detail references.
4.how to make the value editable in ceedit (following the divide 32 rule)
Point to no.2 above, ceedit also type a text / string by CE default. To convert string to number we use common CE Lua command 'tonumber(string)'
Code:  Test :
z = '2.345343235434767'
print(type(z)) > result : string
z1 = tonumber(z)
print(z1) > result : 2.345343235434767
print(type(z1)) > result : number
y = 3E5
print(type(y)) > result : number
y = '3E5'
print(type(y)) > result : string
y1 = tonumber(y)
print(y1) > result : 3e005
print(type(y1)) > result : number
more ='hahaha'
more_n_more = tonumber(more)
print(more_n_more) > result : nil
print(type(more_n_more)) > result : empty (unexpected)

_________________
Singapore Sling + Johnnie Walker + Some Peanuts.... 
