Jump to content

Two problems!


Beluga

Recommended Posts

I'm making a calculator, but I have 2 problems with it.

The first problem is the = button. If I press the = button it shows in display1: value .. + .. value1. but I wanted to let the calculator shows a number (the result)

Here is the code (the = button is the last one (name of the button is calculatorEqual)):

addEventHandler("onClientGUIClick",getRootElement(), 
function(button,state,absx,absy) 
                if(source == calculatorCloseButton) then 
            guiSetVisible(calculatorScreen,false) 
            guiSetVisible(computerScreenTabPanelCalcButton,false) 
            guiSetText(calculatorDisplay,"") 
            guiSetText(calculatorDisplay1,"") 
            guiSetText(calculatorDisplay2,"") 
        elseif(source == calculatorMinimizeButton) then 
            guiSetVisible(calculatorScreen,false) 
            guiSetVisible(computerScreenTabPanelCalcButton,true) 
        elseif(source == calculator1) then 
            addIntoCalculatorEditDisplay("1") 
        elseif(source == calculator2) then 
            addIntoCalculatorEditDisplay("2") 
        elseif(source == calculator3) then 
            addIntoCalculatorEditDisplay("3") 
        elseif(source == calculator4) then 
            addIntoCalculatorEditDisplay("4") 
        elseif(source == calculator5) then 
            addIntoCalculatorEditDisplay("5") 
        elseif(source == calculator6) then 
            addIntoCalculatorEditDisplay("6") 
        elseif(source == calculator7) then 
            addIntoCalculatorEditDisplay("7") 
        elseif(source == calculator8) then 
            addIntoCalculatorEditDisplay("8") 
        elseif(source == calculator9) then 
            addIntoCalculatorEditDisplay("9") 
        elseif(source == calculator0) then 
            addIntoCalculatorEditDisplay("0")            
        elseif(source == calculatorPlus) then 
            local text = guiGetText(calculatorDisplay1) 
            guiSetText(calculatorDisplay,text) 
            guiSetText(calculatorDisplay1,"") 
            guiSetText(calculatorDisplay2,"+") 
        elseif(source == calculatorMin) then 
            local text = guiGetText(calculatorDisplay1) 
            guiSetText(calculatorDisplay,text) 
            guiSetText(calculatorDisplay1,"") 
            guiSetText(calculatorDisplay2,"-") 
        elseif(source == calculatorEqual) then 
            local value = guiGetText(calculatorDisplay) 
            local value1 = guiGetText(calculatorDisplay1) 
            local result = guiGetText(calculatorDisplay2) 
            if result == "+" then 
                guiSetText(calculatorDisplay1,"value .. + .. value1") 
            end 
    end 
end) 

//I tried to delete the "" things but then I got some errors in MTA Script Editor.

My second problem is the marker.

The problem is: When I hit the marker, the calculator pop up at the screen of an other player.

Here is the code:

function markerHit (hitPlayer, matchingDimension) 
        if (source == calculatorMarker) then 
            guiSetVisible(calculatorScreen,true) 
            showCursor(true,true) 
  end 
end 
addEventHandler ("onClientMarkerHit",getRootElement(),markerHit) 

Thanks for your help!

Link to comment
calculatorScreen = guiCreateWindow(0.54654,0.111,0.27,0.8,"Calculator",true) 
guiSetVisible(calculatorScreen,false) 
calculatorDisplay = guiCreateEdit(0.05,0.109,0.79,0.125,"",true,calculatorScreen) 
guiEditSetReadOnly(calculatorDisplay,true) 
calculatorDisplay1 = guiCreateEdit(0.05,0.24,0.79,0.125,"",true,calculatorScreen) 
guiEditSetReadOnly(calculatorDisplay1,true) 
calculatorDisplay2 = guiCreateEdit(0.85123,0.109,0.1,0.257,"",true,calculatorScreen) 
guiEditSetReadOnly(calculatorDisplay2,true) 
guiBringToFront(calculatorDisplay2) 
calculatorCloseButton = guiCreateButton(0.87,0.05,0.0741,0.0377,"x",true,calculatorScreen) 
calculatorMinimizeButton = guiCreateButton(0.7952,0.05,0.0741,0.0377,"-",true,calculatorScreen) 
calculator1 = guiCreateButton(0.01,0.38,0.2,0.112,"1",true,calculatorScreen) 
calculator2 = guiCreateButton(0.25,0.38,0.2,0.112,"2",true,calculatorScreen) 
calculator3 = guiCreateButton(0.46,0.38,0.2,0.112,"3",true,calculatorScreen) 
calculator4 = guiCreateButton(0.01,0.50,0.2,0.112,"4",true,calculatorScreen) 
calculator5 = guiCreateButton(0.25,0.50,0.2,0.112,"5",true,calculatorScreen) 
calculator6 = guiCreateButton(0.46,0.50,0.2,0.112,"6",true,calculatorScreen) 
calculator7 = guiCreateButton(0.01,0.62,0.2,0.112,"7",true,calculatorScreen) 
calculator8 = guiCreateButton(0.25,0.62,0.2,0.112,"8",true,calculatorScreen) 
calculator9 = guiCreateButton(0.46,0.62,0.2,0.112,"9",true,calculatorScreen) 
calculator0 = guiCreateButton(0.25,0.74,0.2,0.112,"0",true,calculatorScreen) 
calculatorPlus = guiCreateButton(0.72,0.38,0.2,0.112,"+",true,calculatorScreen) 
calculatorMin = guiCreateButton(0.72,0.50,0.2,0.112,"-",true,calculatorScreen) 
calculatorEqual = guiCreateButton(0.72,0.74,0.2,0.112,"=",true,calculatorScreen) 

Link to comment

With this code it don't shows errors but it shows as result ìt shows the text: "value .. + ..value1" not the number of the values.

If I delete the "" things it have this errors:

unexpected symbol near '+' (line 47)

and 3x: '' expected near 'end' (line 48, line 49, line 50)

Link to comment
  
function calculatorMarkerHit (hitPlayer, matchingDimension) 
        if (hitPlayer==getLocalPlayer() and matchingDimension) then 
            guiSetVisible(calculatorScreen,true) 
            showCursor(true,true) 
  end 
end 
addEventHandler ("onClientMarkerHit",calculatorMarker,calculatorMarkerHit) 
  

guiSetText(calculatorDisplay1,tonumber(value)+tonumber(value1)) 

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...