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

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

Asked by 8 years ago

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
0
I don't believe there is, sorry. Ryzox 220 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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.

Ad
Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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

0
Well, you could make your own function that takes in two arguments... lightpower26 399 — 8y

Answer this question