Jump to content

Problem with my calculator


FSXTim

Recommended Posts

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

Link to comment
if(source == c1) then 
                number1("1")         
            end 
        else 
            if(source == c1) then 
                number2("1")             
            end 

The same sources!

Link to comment

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

Link to comment

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 

Link to comment

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

Link to comment

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   
  

Link to comment

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

Link to comment

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)

Link to comment

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

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...