Why can't I add a float and integer together?

716 views Asked by At
    on addButtonClicked_(sender)

        if readyForFirst = true then

            set finalNumber to faceNumber's integerValue

            set readyForFirst to false

        else

            set finalNumber to finalNumber + faceNumber's floatValue()

        end if

        set firstNumberClick to true

        set theOperator to "+"

    end addButtonClicked_

For some reason, this part won't work: set finalNumber to finalNumber + faceNumber's floatValue()

I get the error "Can’t make «class ocid» id «data optr000000003701000000000000» into type number. (error -1700)"

Any ideas of why this might be happening? I think it is because it doesn't want me to combine a float with an integer. If this is the reason, why? And how do I fix it? If this isn't the problem, what do you think is?

Thanks!

2

There are 2 answers

0
ShooTerKo On BEST ANSWER

As mentioned in your other questions you have to convert the values (returned as Core Foundation values) to Applescript values:

    if readyForFirst = true then
        set finalNumber to faceNumber's integerValue as integer
        set readyForFirst to false
    else
        set finalNumber to finalNumber + (faceNumber's floatValue as real)
    end if

I don't know if this is a bug that we always need to convert the values, but it did work for your other questions...

Greetings, Michael / Hamburg

0
Hana Bzh On

like integerValue, floatValue doesn't need ()

try

set finalNumber to finalNumber + faceNumber's floatValue

instead of

set finalNumber to finalNumber + faceNumber's floatValue()