Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CalculatorFrame = script.Parent:WaitForChild("CalculatorFrame")
- local ButtonsFrame = CalculatorFrame:WaitForChild("ButtonsFrame")
- local ListFrame = ButtonsFrame:WaitForChild("ListLayout")
- local Input = CalculatorFrame:WaitForChild("Input")
- local SymbolData = require(script.SymbolData)
- local CalculateModule = require(script.MainModule)
- local Number
- local Calculation = ""
- Input.Text = ""
- function Calculate(String)
- local Ran, Num = pcall( CalculateModule, String )
- if not Ran then Input.Text = "Invalid Calculation" return end
- return Num
- end
- for _, Button in pairs(ListFrame:GetChildren()) do
- if not Button:IsA("TextButton") then continue end
- Button.MouseButton1Click:Connect(function()
- if tonumber(Button.Name) then
- if tonumber(Input.Text) then
- Input.Text = Input.Text..Button.Name
- else
- Input.Text = Button.Name
- end
- if Number == nil then
- Number = tostring(tonumber(Button.Name))
- else
- Number = Number..tostring(tonumber(Button.Name))
- end
- Calculation = Calculation..tostring(Button.Name)
- elseif Button.Name == "=" then
- Input.Text = Calculate(Calculation)
- elseif Button.Name == "C"then
- Calculation = ""
- Number = nil
- Input.Text = ""
- else
- if Number == nil then return end
- local CodeSymbol = SymbolData[Button.Name]
- if Calculation == nil then
- return
- else
- Calculation = Calculation..CodeSymbol
- end
- Number = nil
- Input.Text = Button.Name
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement