Check box does not react

Hi,
Again I have a problem. I want to have that the user of the app can choose which size he typ in and then the script should convert the size into kilograms. Here is the script:

on clicked theObject
	if (get name of theObject) is "Force" then
		--get the values
		set mass_value to string value of text field "field_mass_value" of window "F_ma" as number --get the mass value out of the window and it converts into a number
		set acceleration_value to string value of text field "field_acceleration_value" of window "F_ma" as number --get the acceleration value and it converts into a number
		--end of getting the value
		--convert the mass into kilogram
		if state of button "Tons" of window "F_ma" is 1 then --if the user clicked into the "Tons" button		
			set mass_value to mass_value * 1000 --convert the mass_value from ton into kilogram
		else if state of button "Grams" of window "F_ma" is 1 then --if the user clicked into the "Grams" button
			set mass_value to mass_value / 1000 --convert the mass_value from grams into kilogram
		end if
		--end of conversion
		--calculation of the force value
		set force_result to mass_value * acceleration_value --calculate the force (F=m*a)
		set force_display to (force_result as text) & " N" --puts in the unit and convert it into a text
		display dialog mass_value buttons {"Close", "Save and Close"} default button 1
		--end of conversion
	end if
end clicked

I covered there for the orders the given examples.
Please help me with me problem and thank you for your time and help.
best regrads
Marcel

PS: If a screenshot is needed, feel free to contact me.

I guess, you want to display the result variable force_display


.
display dialog force_display buttons {"Close", "Save and Close"} default button 1
.

You should add some error handling in case the user types other characters than ciphers

Note: if you need a number value of a text field, use float value instead of string value without any coercion, e.g.


set mass_value to float value of text field "field_mass_value" of window "F_ma"

thank you for his help yes you guessed right, but the problem is that this part do not work:

if state of button "Tons" of window "F_ma" is 1 then --if the user clicked into the "Tons" button		
			set mass_value to mass_value * 1000 --convert the mass_value from ton into kilogram
		else if state of button "Grams" of window "F_ma" is 1 then --if the user clicked into the "Grams" button
			set mass_value to mass_value / 1000 --convert the mass_value from grams into kilogram
		end if

When I typed in for example field_mass_value: 10, check box Tons and field_acceleration_value: 10
then the result has do be 100.000, but the result is 10

second when I selected kilograms, which has no worth the result is 10, too. So I guess, that the calculation does not work, too.

--calculation of the force value
		set force_result to mass_value * acceleration_value --calculate the force (F=m*a)
		set force_display to (force_result as text) & " N" --puts in the unit and convert it into a text
		display dialog force_display buttons {"Close", "Save and Close"} default button 1
		--end of conversion

and the buttons Close and Save and Close do not arrive to.

thank you for any advice Marcel

The syntax is correct, I tested it with a test project.
Same question: are the buttons Tons and Grams named in Interface Builder.
You can use log messages to get some temporary results like


.
if state of button "Tons" of window "F_ma" is 1 then --if the user clicked into the "Tons" button        
	set mass_value to mass_value * 1000 --convert the mass_value from ton into kilogram
	log "Tons: " & mass_value
else if state of button "Grams" of window "F_ma" is 1 then --if the user clicked into the "Grams" button
	set mass_value to mass_value / 1000 --convert the mass_value from grams into kilogram
	log "Grams: " & mass_value
end if
.

Another problem could be a format convention clash:
AppleScript uses a dot as decimal point, the german version of the OS uses a comma.
A coercion number to text could cause unexpected behavior

I do not know why, but the script works. But thank you for your help.

Log the value of your check box and look what is returned in the console. I have noticed in some that I have bound to a user default that I am getting a return of true or false when the user changes it instead of 1 or 0 so have added code in to correct this when reading the result.