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

Calculator Script not working, why? [Fixed]

Asked by
Xianon 105
10 years ago

I'm doing a Calculator and making it work with a single script and 2 int Values, it seems that onClick is not detecting my clicks because maybe i'm using it incorrectly, this script is incomplete, but by far i tested and i can't continue knowing it won't work.

local index = script.Parent.result
local in1 = script.Parent.in1
local in2 = script.Parent.in2
local in3 = script.Parent.in3
local in4 = script.Parent.in4
local in5 = script.Parent.in5
local in6 = script.Parent.in6
local in7 = script.Parent.in7
local in8 = script.Parent.in8
local in9 = script.Parent.in9
local inp = script.Parent.inp
local ins = script.Parent.ins
local ind = script.Parent.ind
local v1 = script.Parent.v1
local v2 = script.Parent.v2
inp = false
ins = false
ind = false
v1 = false
v2 = false
print("HardWare is available and Online") 


function onClick(in1) -- Click Event --
    print("Click Detected")
    index.Text = ("1") -- Puts the value on the GUI --
    v1.Value = ("1") -- Input the value to an int Value like in C++ --


    if (inp == true)then -- Checks if inp is true to declare it a Addition Operation --
        r = v1 + v2 -- Does the math --
        index.Text = r -- Output the result --
    end
    if (v1 == true)then -- check if v1 is already being used so it input it on v2 --
        v2.Value = ("1")
    end
    in1.MouseButton1Click:connect(onClick)

    function onClick(in2)
    index.Text = ("2")
    v1.Value = ("2")
    if (inp == true)then
        r = v1 + v2
        index.Text = r
    end
    if (v1 == true)then
        v2.Value = ("2")
    end
    in2.MouseButton1Click:connect(onClick)

    function onClick(in3)
    index.Text = ("3")
    v1.Value = ("3")
    if (inp == true)then
        r = v1 + v2
        index.Text = r
    end
    if (v1 == true)then
        v2.Value = ("3")

    end
    in3.MouseButton1Click:connect(onClick)
    end
    end
end


















0
Woah, what are you doing? This doesn't structure at all in a good way BlueTaslem 18071 — 10y
0
What do you mean? Xianon 105 — 10y
0
You're not initializing your MouseButton1Click connections. It has a nice function, but in what you've given us, its never called. GoldenPhysics 474 — 10y
0
Oh, i see, i try to fix it. Xianon 105 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

Looks like you are "ends" in the wrong place because line 24 and down is one whole function. i fixed it for you(hopefully):

local index = script.Parent.result
local in1 = script.Parent.in1
local in2 = script.Parent.in2
local in3 = script.Parent.in3
local in4 = script.Parent.in4
local in5 = script.Parent.in5
local in6 = script.Parent.in6
local in7 = script.Parent.in7
local in8 = script.Parent.in8
local in9 = script.Parent.in9
local inp = script.Parent.inp
local ins = script.Parent.ins
local ind = script.Parent.ind
local v1 = script.Parent.v1
local v2 = script.Parent.v2
inp = false
ins = false
ind = false
v1 = false
v2 = false
print("HardWare is available and Online") 


function onClick(in1) -- Click Event --
    print("Click Detected")
    index.Text = ("1") -- Puts the value on the GUI --
    v1.Value = ("1") -- Input the value to an int Value like in C++ --


    if (inp == true)then -- Checks if inp is true to declare it a Addition Operation --
        r = v1 + v2 -- Does the math --
        index.Text = r -- Output the result --
    end
    if (v1 == true)then -- check if v1 is already being used so it input it on v2 --
        v2.Value = ("1")
    end end
    in1.MouseButton1Click:connect(onClick)

    function onClick(in2)
    index.Text = ("2")
    v1.Value = ("2")
    if (inp == true)then
        r = v1 + v2
        index.Text = r
    end
    if (v1 == true)then
        v2.Value = ("2")
    end end
    in2.MouseButton1Click:connect(onClick)

    function onClick(in3)
    index.Text = ("3")
    v1.Value = ("3")
    if (inp == true)then
        r = v1 + v2
        index.Text = r
    end
    if (v1 == true)then
        v2.Value = ("3")

    end end
    in3.MouseButton1Click:connect(onClick)
Ad

Answer this question