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

What is wrong with my MetaTable Arguments?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I'm trying to make a simple equation solver, and I get the following error:

  • Workspace.Script:6: attempt to call local 'A' (a number value)

"A" is a Number Value since I placed numbers only as Arguments. What am I doing wrong? Any and all help is appreciated.

local Equation = {
    C = 0;
}

function Equation.SolveForC(A,x,B,y)
    Equation.C = A(x) + B(y)
    print(Equation.C)
end

Equation.SolveForC(2,3,2,3)
0
Your problem is A(x). Lua treats this as a function call, when you actually want to multiply. Instead, do "Equiation.C = A*x + B*y" GoldenPhysics 474 — 8y
0
Why do you always post comments instead of answers, GoldenPhysics? ProgrammerA10 85 — 8y
0
They're shorter. GoldenPhysics 474 — 8y
0
There are no metatables involved here BlueTaslem 18071 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

The answer is simple: You did not use correct Lua formatting for multiplication. In Lua, it is only ever x * y, never x(y) or y(x). Here is the corrected code:

local Equation = {
    C = 0;
}

function Equation.SolveForC(A,x,B,y)
    Equation.C = A*x + B*y
    print(Equation.C)
end

Equation.SolveForC(2,3,2,3)

If this helped, please accept this answer.

0
Thank you so much! lacikaturai 89 — 8y
0
You're welcome! ProgrammerA10 85 — 8y
Ad

Answer this question