Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Arithmetic as variable?

I have function in which perform arithmetic on standart numbers.

function arithmetic(formula)
	x = 1
	y = 10
	z = formula
	print(z)
end

arithmetic(x+y)

The problem is: it starts to count in function variables, when x and y are nil, and error happens because x and y are nil at the first line.

So i want to perform arithmetic only when i want to, in this case only on line 4.

1 answer

x & y are not defined globally in the script in line 8. When you're calling a function, it takes in arguments for the function to play with.

function Arithmetic(x, y) -- Parameters for arguments
	local Solution = x + y
	print(Solution)
end
-- At this point, the function is defined; the output will spit out the solution when it is called.

Arithmetic(1, 10) -- Here, the defined function "Arithmetic" is called, taking 1 and 10 for x and y respectively.

11

This discussion is preserved as it was. New answers, comments, and votes are closed.