Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"Expected identifier, got function." What!? Help! [SOLVED]

Asked by 5 years ago
Edited 5 years ago

Scroll Down To See Problem

caculations = {n1 = "", operation = "", n2 = ""}


--Buttons
B0 = script.Parent.Buttons.B0.ClickDetector
B1 = script.Parent.Buttons.B1.ClickDetector
B2 = script.Parent.Buttons.B2.ClickDetector
B3 = script.Parent.Buttons.B3.ClickDetector
B4 = script.Parent.Buttons.B4.ClickDetector
B5 = script.Parent.Buttons.B5.ClickDetector
B6 = script.Parent.Buttons.B6.ClickDetector
B7 = script.Parent.Buttons.B7.ClickDetector
B8 = script.Parent.Buttons.B8.ClickDetector
B9 = script.Parent.Buttons.B9.ClickDetector
Bdivide = script.Parent.Buttons.Operations.Bdivide.ClickDetector
Bplus = script.Parent.Buttons.Operations.Bplus.ClickDetector
Bequals = script.Parent.Buttons.Operations.Bequals.ClickDetector
Btimes = script.Parent.Buttons.Operations.Btimes.ClickDetector
Bminus = script.Parent.Buttons.Operations.Bdivide.ClickDetector

product = 0

operationpresent = false

chosenOperationID = 0

MAX_DIGITS = 12

-- ID's
minus = 1
plus = 3
times = 4
divide = 5


-- Tables, Varibles And Set Up ^

-- OPERATIONS: - + / * =

-- Player Picks Operation And Two Numbers

function N0()
    if operationpresent == false then
    caculations.n1 = caculations.n1.."0"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."0"
    print(caculations.n1.." Number 2")
end     
end

function N1()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."1"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."1"
    print(caculations.n1.." Number 2")
    end
end

function N2()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."2"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."2"
    print(caculations.n1.." Number 2")
    end
end

function N3()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."3"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."3"
    print(caculations.n1.." Number 2")
    end
end

function N4()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."4"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."4"
    print(caculations.n1.." Number 2")
    end
end

function N5()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."5"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."5"
    print(caculations.n1.." Number 2")
    end
end

function N6()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."6"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."6"
    print(caculations.n1.." Number 2")
    end
end

function N7()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."7"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."7"
    print(caculations.n1.." Number 2")
    end
end

function N8()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."8"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."8"
    print(caculations.n1.." Number 2")
    end
end

function N9()
        if operationpresent == false then
    caculations.n1 = caculations.n1.."9"
    print(caculations.n1.." Number 1")
    else
    caculations.n2 = caculations.n2.."9"
    print(caculations.n1.." Number 2")
    end
end

function equals()
    caculate()
    print(product)
    caculations.n1 = ""
    caculations.n2 = ""
    caculations.operation = "0"
    product = "0"
end

function


-- Caculation
function caculate()
    if caculations.n1 == "0" and caculations.n2 == "0" and caculations.operation == "/" then
        warn("Bad Caculation. 0/0 Is Not Possible.")
    else
if caculations.operation == "-" then
product = caculations.n1 - caculations.n2
print("Da Answer Is "..product)
else
if caculations.operation == "+" then
product = caculations.n1 + caculations.n2
print("Da Answer Is "..product)
else
if caculations.operation == "*" then
product = caculations.n1 * caculations.n2
print("Da Answer Is "..product)
else
if caculations.operation == "/" then
product = caculations.n1 / caculations.n2
print("Da Answer Is "..product)
equals()
end
end
end
end
end
end

--Events
B0.MouseClick:Connect(N0)
B1.MouseClick:Connect(N1)
B2.MouseClick:Connect(N2)
B3.MouseClick:Connect(N3)
B4.MouseClick:Connect(N4)
B5.MouseClick:Connect(N5)
B6.MouseClick:Connect(N6)
B7.MouseClick:Connect(N7)
B8.MouseClick:Connect(N8)
B9.MouseClick:Connect(N9)
Bdivide.MouseClick:Connect(divide)
Bminus.MouseClick:Connect(minus)
Bplus.MouseClick:Connect(plus)
Btimes.MouseClick:Connect(times)
Bequals.MouseClick:Connect(equals)


Alright, so i've been trying to make a Calculator with just 4 operations: = + / *. The calculator should do the following when done (Yes its uncompleted) - Add all digits to calculation. (YEP) - Able to Plus, Divide, Equal, And Multiply. (Almost There!) - Able to show numbers on a SurfaceGui. - Able to Join digits Each Time A Digit Is Pressed. e.g 0 > 00 > 000 > 0000 (YEP) - Able to show a product. Thing is, on:

function caculate()

(on line 155) i spotted an error on "function", it said: "Expected identifier, got function". WOAH! My mind went bonkers there. Ive never encountered anything like it. I Could not think of anything to do! The script is above for people to inspect it ^ Please Help!

  • Polandball45

P.S: I know its a bit large and messy with little to no try of compacting it.

0
Fix the goddamn indentation User#24403 69 — 5y
0
on line 151 you are declaring a function but you didn't give it a variable name, try removing the "function" at line 151 kisty1 111 — 5y
0
yeah why do you just have a random function declaration ihatecars100 502 — 5y

1 answer

Log in to vote
0
Answered by
Isaque232 171
5 years ago
Edited 5 years ago

Take a look at the line 151 at your script since there's a random function declaration which might be what's causing the issue with your script.

If that's not the issue then make sure to advice! Hopefully that solves it, and if it did then make sure to accept the answer!

0
Huh. Well. I Sure did waste everyones time :/ . But Thanks Anyway! (how did i not notice that?) Polandball45 17 — 5y
Ad

Answer this question