Hello,
I thought of a concept idea of a working calculator in roblox studio. I want to hear what you guys think!
local text = script.Parent.Text
local possibleArithmitic = {"+", "-", "*", "/"}
local possibleNumbers = {"1","2","3","4","5","6","7","8","9","0"}
local symbol
local Numbers = {}
local function solve()
table.clear(Numbers)
symbol = ""
text = script.Parent.Text
for i,v in pairs(possibleArithmitic) do
if string.find(text.Text, v) then
symbol = v
local splitNumber = string.split(text.Text, v)
for i,v in pairs(splitNumber) do
table.insert(Numbers, v)
end
end
end
-- I think I could utilize a for loop here but I don't know how!
if symbol == "+" then
return Numbers[1] + Numbers[2]
end
if symbol == "-" then
return Numbers[1] - Numbers[2]
end
if symbol == "*" then
return Numbers[1] * Numbers[2]
end
if symbol == "/" then
return Numbers[1] / Numbers[2]
end
end
script.Parent.Equals.MouseButton1Up:Connect(function()
text.Text = solve()
end)
script.Parent.Clear.MouseButton1Up:Connect(function()
text.Text = ""
end)
Basically this can only use one algorithmic term(+,-,*,/). To be able to di multiple terms, I need to figure out how to utilize a for loop on line 22-34.
Please let me know if you know how to make it!