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

Is there an easier way to do basic math in roblox lua?

What I want to know Is if there is a way around having to do math like this:

      Num = Num + 1

I know that in JavaScript you can just add a plus before the equal sign to accomplish the above function

      Num += 1

Is there anything like this in lua?

2 comments

0

calling a function that takes in the value and just adds 1 can work as well.

1 answer

Not really, and I don't see how

Num = Num + 1

is considered hard to do. You could, however, do this if you use it a lot:

function AddNumbers(Num1, Num2)
	Answer = Num1 + Num2
	return Answer
end

--Your code 

local CoolValueInsertHere = 69
local OtherReallyCoolValueToAdd = 1

Value = AddNumbers(CoolValueInsertHere, OtherReallyCoolValueToAdd)
print(Value)

--Prints 70

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