brocky Posted November 13, 2015 Share Posted November 13, 2015 I have a problem with a code, Its a simple calculator to substract numbers, but the problem is that it doesn't give the required/correct answer. editbox1 = guiCreateEdit(22, 41, 135, 24, "", false, window1) editbox2 = guiCreateEdit(21, 80, 136, 24, "", false, window1) buttonSub = guiCreateButton(148, 250, 110, 26, "Subtraction", false, window1) function substraction() if buttonSub == source then num1 = guiGetText ( editbox1 ) num2 = guiGetText ( editbox1 ) local subtheAnswer = num1 - num2 outputChatBox("Subtraction answer: "..subtheAnswer) end end addEventHandler("onClientGUIClick", buttonSub, substraction, false) Hope you understood Link to comment
Addlibs Posted November 13, 2015 Share Posted November 13, 2015 num1 = guiGetText ( editbox1 ) num2 = guiGetText ( editbox1 ) Both num1 and num2 come from the same edit box, which means you're just doing editbox1 value - editbox1 value (i.e. a-a) Change line 9 to num2 = guiGetText ( editbox2 ) --editbox2 not editbox1 Link to comment
brocky Posted November 14, 2015 Author Share Posted November 14, 2015 Oh, thanks! I din't paid Link to comment
</Mr.Tn6eL> Posted November 14, 2015 Share Posted November 14, 2015 Use tonumber local num1 = tonumber(guiGetText ( editbox1 )) local num2 = tonumber(guiGetText ( editbox2 )) if num1 and num2 then local subtheAnswer = num1 - num2 outputChatBox("Subtraction answer: "..subtheAnswer) else outputChatBox("Invalid input") end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now