7

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.

4
  • 2
    What do you mean, "use forever in memory" ? Commented Nov 15, 2010 at 0:55
  • 4
    Please note that the language is named "Lua", not "LUA". It is the proper name of the Earth's moon, in Portuguese. Commented Nov 15, 2010 at 8:41
  • If you want to edit your question, you can click the "edit" link below the tags. Give it a try. Commented Nov 15, 2010 at 11:17
  • 1
    what game engine or environment are you working in? that seems probably important to your question Commented Apr 21, 2017 at 20:06

4 Answers 4

15

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.

Sign up to request clarification or add additional context in comments.

2 Comments

One thing: you cannot write the colon after "do", that's what you would do in Python, but not in Lua
Also, no semicolons required in Lua even when you have multiple statements on the same line.
1

There are two ways to use infinite loop:

repeat
-- do something
until false

-- or --

while true do
-- do something
end

Comments

0

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

1 Comment

while this is factually accurate, the above code will block the thread, and is unlikely the right solution to the person's problem
-1

Trivial loop function:

function loop()
    -- your code here
    while true do
        -- your loop code there
    end
end

More not trivial loop:

function loop ()
    -- your loop code there
    return loop()
end

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.