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

Does RbxLua have a method for adding without an extensive line of code?

I know ScriptingHelpers is a place to submit scripts and get them fixed, but after 3 days of throughout search on the Internet, I still have not found an answer to my question.

Does RbxLua have a method similar to the '++' in C?

Because I keep using that method in a more conventional and longer way (Variable = Variable + Increment).

Any feedback will be appreciated. If you think my question is inadequate, comment about it and I will take it down.

:)

  • TheArmoredReaper

1 comment

0

I don't believe there is, sorry.

2 answers

✓ Accepted answer

Lua doesn't have a unary increment operator, so you'll have to make do with var = var + 1. The reason is that expressions like that with complex expressions to be assigned to are a bit heavy on lexers / token filters, and would be almost excessive with a lightweight language like Lua.

No.

This is basically to keep Lua simple. While it's clear what would be done in something like

a += 1

What does

a.b[c] += 1

do?

You can have metamethods handling each get... and there are lots of reasons (mostly performance, but also semantics, because of the complexity that metamethods can allow) you'd want it to have a different behavior from

a.b[c] = a.b[c] + 1

Here's a Stackoverflow answer on this topic

1 comment

0

Well, you could make your own function that takes in two arguments...

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