开发者

How to make an infinite loop in Lua code?

I have three local functions that I want to use forever in 开发者_开发百科memory:

proxy:PlayerParamRecover();
proxy:PlayerRecover();
proxy:EnableInvincible(10000,true);

I'm not sure how to add them in an infinite loop.


You want a while loop:

while true do
  proxy:PlayerParamRecover()
  proxy:PlayerRecover()
  proxy:EnableInvincible(10000,true)
end

Additional information here

Note that, since the while loop will always have control of the program after entering that loop, any code you write after it won't ever execute. Infinite loops are only useful in extreme cases - make sure that what you want to do warrants it.


There are two ways to use infinite loop:

repeat
-- do something
until false

-- or --

while true do
-- do something
end


If you wanted to say "Hello" in the command bar every second, infinitely, or something like that, you would use the format below:

    while true do
    -- whatever
    end

For example,

    while true do
    print("Hello")
    wait(1)
    end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜