FSXTim Posted May 31, 2012 Posted May 31, 2012 Hello, I have some problems with my calculator script. When the player enter a arithmetic operator (it calls 'zwischeneingabe in my script), the new numbers, which the player enter, have to be in the second edit ('eingabe2'), but the numbers are entered in the first edit ('eingabe1') function rechnerKlick (state) if state == "left" then if source == cRefresh then guiSetText(eingabe1,"") guiSetText(eingabe2,"") guiSetText(zwischeneingabe,"") guiSetText(ergebnis,"") end local ze = guiGetText(zwischeneingabe) if ze ~= "" or ze ~= nil then if(source == c1) then number1("1") end else if(source == c1) then number2("1") end end end end addEventHandler("onClientGUIClick", getRootElement(), rechnerKlick) function number1 (number1) local text = guiGetText(eingabe1) guiSetText (eingabe1,""..text..""..number1.."") end function number2 (number2) local text = guiGetText(eingabe2) guiSetText (eingabe2,""..text..""..number2.."") end Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 if(source == c1) then number1("1") end else if(source == c1) then number2("1") end The same sources!
Flaker Posted May 31, 2012 Posted May 31, 2012 (edited) omg, i though problem in same btns Edited May 31, 2012 by Guest
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 Em, it's still not working: Same function, but the different ways. 1. When the player doesn't enter a arithmetic operator and press the Button 'c1', then ... 2. When the player enter a arithmetic operator and press the Button 'c1', then ... Do you understand me? Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 Try this, and check DebugString... function rechnerKlick (state) if state == "left" then if (source == cRefresh) then guiSetText(eingabe1,"") guiSetText(eingabe2,"") guiSetText(zwischeneingabe,"") guiSetText(ergebnis,"") outputDebugString("Refresh") elseif (source == c1) then outputDebugString("C1") local ze = guiGetText(zwischeneingabe) if ze ~= "" or ze ~= nil then outputDebugString("Ze nil") number1("1") else number2("1") outputDebugString("Ze not nil") end end end end addEventHandler("onClientGUIClick", getRootElement(), rechnerKlick) function number1 (number1) local text = guiGetText(eingabe1) guiSetText (eingabe1,""..text..""..number1.."") outputDebugString("Function Number1") end function number2 (number2) local text = guiGetText(eingabe2) guiSetText (eingabe2,""..text..""..number2.."") outputDebugString("Function Number2") end
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 If I don't enter a arithmetic operator, the debugstring sais that: 'C1' 'Ze nil' 'Function Number 1' If I enter a arithmetic operator, the debugstring sais that: 'C1' 'Ze nil' 'Function Number 1' The same! Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 So, i think problem is in it: local ze = guiGetText(zwischeneingabe) if ze ~= "" or ze ~= nil then What is zwischeneingabe (Edit, Memo, Or what?) It would be nice if you give full code.
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 It's a Edit, here is the full code: x,y = guiGetScreenSize() rechner_Window = guiCreateWindow(x/10.0 - 110,y/2.5 - 165,220,330,"",false) c1 = guiCreateButton(0.1636,0.3333,0.1455,0.0939,"1",true,rechner_Window) cPlus = guiCreateButton(0.6909,0.3333,0.1455,0.0939,"+",true,rechner_Window) cMinus = guiCreateButton(0.6909,0.4455,0.1455,0.0939,"-",true,rechner_Window) cMal = guiCreateButton(0.6909,0.5606,0.1455,0.0939,"x",true,rechner_Window) cRefresh = guiCreateButton(0.3364,0.6758,0.1455,0.0939,"C",true,rechner_Window) cDurch = guiCreateButton(0.6909,0.6758,0.1455,0.0939,"/",true,rechner_Window) cGleich = guiCreateButton(0.5136,0.6758,0.1455,0.0939,"=",true,rechner_Window) eingabe1 = guiCreateEdit(0.1636,0.1182,0.2727,0.0758,"",true,rechner_Window) guiEditSetReadOnly(eingabe1,true) guiEditSetMaxLength(eingabe1,10) eingabe2 = guiCreateEdit(0.5682,0.1182,0.2727,0.0758,"",true,rechner_Window) guiEditSetMaxLength(eingabe2,10) guiEditSetReadOnly(eingabe2,true) guiEditSetMaxLength(eingabe2,10) zwischeneingabe = guiCreateEdit(0.4409,0.1182,0.1182,0.0758,"",true,rechner_Window) guiEditSetReadOnly(zwischeneingabe,true) ergebnis = guiCreateEdit(0.1636,0.203,0.6773,0.0758,"",true,rechner_Window) guiEditSetReadOnly(ergebnis,true) function rZeichen (state) if state == "left" then if(source == cPlus) then guiSetText(zwischeneingabe,"+") elseif(source == cMinus) then guiSetText(zwischeneingabe,"-") elseif(source == cMal) then guiSetText(zwischeneingabe,"x") elseif(source == cDurch) then guiSetText(zwischeneingabe,"/") end end end addEventHandler("onClientGUIClick", getRootElement(), rZeichen) function rechnerKlick (state) if state == "left" then if (source == cRefresh) then guiSetText(eingabe1,"") guiSetText(eingabe2,"") guiSetText(zwischeneingabe,"") guiSetText(ergebnis,"") outputDebugString("Refresh") elseif (source == c1) then outputDebugString("C1") local ze = guiGetText(zwischeneingabe) if ze ~= "" or ze ~= nil then outputDebugString("Ze nil") number1("1") else number2("1") outputDebugString("Ze not nil") end end end end addEventHandler("onClientGUIClick", getRootElement(), rechnerKlick) function number1 (number1) local text = guiGetText(eingabe1) guiSetText (eingabe1,""..text..""..number1.."") outputDebugString("Function Number1") end function number2 (number2) local text = guiGetText(eingabe2) guiSetText (eingabe2,""..text..""..number2.."") outputDebugString("Function Number2") end Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 In your code, "zwischeneingabe" always is nil, because in function "number1/number2" we enter text in the "eingabe2", and "zwischeneingabe" does not change!
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 Can you give me the correct code, please? Because I do not fully understand what you mean! Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 "zwischeneingabe" change only in "rZeichen" function, but this function isn't executed by pressing the "c1"! So zwischeneingabe dosn't change Try to push C1 then cPlus and then C1 And check Debug
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 I already tried, and then: 'C1' 'Ze nil' 'Function Number 1' But the numbers are in 'eingabe1' and not in 'eingabe2'! Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 Hmm... Give a screenshot of ur Calculator plz... And say me where is eingabe1 where is eingabe2 and where is zwischeneingabe on the Screenshot... (Just i haven't MTA on my computer now >< and can't test ur script )
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 11 = eingabe1 + = zwischeneingabe (couldn't enter) = einagbe2 the long line = ergebnis Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 Try this: local x,y = guiGetScreenSize() rechner_Window = guiCreateWindow(x/10.0 - 110,y/2.5 - 165,220,330,"",false) c1 = guiCreateButton(0.1636,0.3333,0.1455,0.0939,"1",true,rechner_Window) cPlus = guiCreateButton(0.6909,0.3333,0.1455,0.0939,"+",true,rechner_Window) cMinus = guiCreateButton(0.6909,0.4455,0.1455,0.0939,"-",true,rechner_Window) cMal = guiCreateButton(0.6909,0.5606,0.1455,0.0939,"x",true,rechner_Window) cRefresh = guiCreateButton(0.3364,0.6758,0.1455,0.0939,"C",true,rechner_Window) cDurch = guiCreateButton(0.6909,0.6758,0.1455,0.0939,"/",true,rechner_Window) cGleich = guiCreateButton(0.5136,0.6758,0.1455,0.0939,"=",true,rechner_Window) eingabe1 = guiCreateEdit(0.1636,0.1182,0.2727,0.0758,"",true,rechner_Window) guiEditSetReadOnly(eingabe1,true) guiEditSetMaxLength(eingabe1,10) eingabe2 = guiCreateEdit(0.5682,0.1182,0.2727,0.0758,"",true,rechner_Window) guiEditSetMaxLength(eingabe2,10) guiEditSetReadOnly(eingabe2,true) guiEditSetMaxLength(eingabe2,10) zwischeneingabe = guiCreateEdit(0.4409,0.1182,0.1182,0.0758,"",true,rechner_Window) guiEditSetReadOnly(zwischeneingabe,true) ergebnis = guiCreateEdit(0.1636,0.203,0.6773,0.0758,"",true,rechner_Window) guiEditSetReadOnly(ergebnis,true) function rZeichen (state) if(source == cPlus) then guiSetText(zwischeneingabe,"+") elseif(source == cMinus) then guiSetText(zwischeneingabe,"-") elseif(source == cMal) then guiSetText(zwischeneingabe,"x") elseif(source == cDurch) then guiSetText(zwischeneingabe,"/") end end addEventHandler("onClientGUIClick", getRootElement(), rZeichen) function rechnerKlick (state) if (source == cRefresh) then guiSetText(eingabe1,"") guiSetText(eingabe2,"") guiSetText(zwischeneingabe,"") guiSetText(ergebnis,"") outputDebugString("Refresh") elseif (source == c1) then addTextInFild ("1") end end addEventHandler("onClientGUIClick", getRootElement(), rechnerKlick) function addTextInFild (Number) local zwText = guiGetText(zwischeneingabe) if not(zwText == "") then guiSetText (eingabe1,guiGetText ( eingabe1 )..""..Number) outputDebugString("eingabe1") else guiSetText (eingabe2,guiGetText ( eingabe2 )..""..Number) outputDebugString("eingabe2") end end
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 This doesn't work completly, I changed something: function addTextInFild (Number) local zwText = guiGetText(zwischeneingabe) if not(zwText == "") then guiSetText (eingabe2,""..Number.."") outputDebugString("eingabe1") else guiSetText (eingabe1,""..guiGetText(eingabe2)..""..Number.."") outputDebugString("eingabe2") end end It works now, but the problem is, that I cannot enter more then one number in 'eingabe1' and 'eingabe2'! I hope you can help me one more time again. Greets
Flaker Posted May 31, 2012 Posted May 31, 2012 Try this: function addTextInFild (Number) local zwText = guiGetText(zwischeneingabe) if (zwText == "") then guiSetText (eingabe1,""..guiGetText ( eingabe1 )..""..Number.."") outputDebugString("eingabe1") else guiSetText (eingabe2,""..guiGetText ( eingabe2 )..""..Number.."") outputDebugString("eingabe2") end end U gave me full code? (There are more buttons on screenshot, than at ur code)
FSXTim Posted May 31, 2012 Author Posted May 31, 2012 Thanks for your help, you took a lot of time to help me, thanks, you are great! Everything is working now. U gave me full code? (There are more buttons on screenshot, than at ur code) I didn't give you the labels/buttons, which are not important for calculator script. Greets
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