Home AMX User Forum NetLinx Studio

falling down auto type cast float to integer

Odd thing...

an_Int = a_Float*255.0
an_Int = 255.0

Compiler says:

ERROR: File.axs(1): C10512: Cannot convert type [FLOAT] to [INTEGER]
ERROR: File.axs(2): C10533: Illegal assignment statement
WARNING: File.axs(2): C10571: Converting type [FLOAT] to [INTEGER]

So my question is: Why does it fail on the first conversion not the second? and how do I fix it?

Comments

  • Odd thing...

    an_Int = a_Float*255.0
    an_Int = 255.0

    Compiler says:

    ERROR: File.axs(1): C10512: Cannot convert type [FLOAT] to [INTEGER]
    ERROR: File.axs(2): C10533: Illegal assignment statement
    WARNING: File.axs(2): C10571: Converting type [FLOAT] to [INTEGER]

    So my question is: Why? and how do I fix it?
    The compiler will not test if the result of the operation is a full number (i.e. 255.0). The compiler just sees in both operations a pass of a Float value into an Integer, which is not allowed.

    A TYPE_CAST() will "cut off" the values after the comma
    an_Int = TYPE_CAST(a_Float*255.0)
    an_Int = TYPE_CAST(255.0) // an_Int now is 255
    
  • Thanks alot.
Sign In or Register to comment.