我仍然是Lua的新手,对var中的var有一个问题。
我如何计算这个值:?
A=1
X=A
X=X+1如你所见:
此计算将导致
A=A+1但这对我不起作用。
我想我必须以某种方式格式化汽车。
我之所以这样做,是因为我希望能够在必要时更改另一个var中的var。
发布于 2020-01-14 13:40:13
=运算符做两件事:
上的变量
为了说明这一点,请考虑以下示例:
A = 1 -- A is now 1
X = A + A + A -- X is now 3, and A hasn't changed
X = X + 1 -- X is now 4, and A hasn't changed现在让我们看一下你的原始代码,并用简单的语言写出它的意思。
A=1 -- Create a variable 'A' and assign it the value of one
X=A -- Create the variable 'X' and assign it the current value of 'A'
X=X+1 -- Change 'X' by assigning it the current value of 'X' plus one注意,这些注释对计算机来说读起来像是“指令”,而不是数学公式。Lua (和一般的编程)应该解释为从上到下执行的一组指令。
然而,正如埃戈尔·斯克里普图诺夫在之前的评论中所暗示的那样,表格的行为是不同的。有关表的不同之处的更详细解释,请参阅Programming in Lua - Chapter 2.5。
https://stackoverflow.com/questions/59723537
复制相似问题