How do I make a script that can run through a list of functions that I can stop at will? Lua 5.1 LGS

58 Views Asked by At

So I am using LGS to write macro scripts and I am trying to make a script that I can stop without having to run through then entire script. Assume a very, very long script.

Normally, the script would have to execute to completion in complex scripts. I want to make a table with functions in it that I can call them in order but stop execution at will.

--Arbitary code:
TextEditor = {39393, 739937}

SomeString = "A very long novel"

WriteString = function(str)
    --Some code to type to a text editor
end

OtherFunction = function(arg1, arg2)
 -- do something
end

AnotherFunction = function(arg1, arg2, arg3)
   -- do something
end

ReadSomething = function()
   -- arbitrary code
end
-- Problem:
Script = {
   MoveMouseTo(TextEditor)
   WriteString(SomeString)
   OtherFunction(arg1, arg2)
   AnotherFunction(arg1, arg2, arg3)
   ReadSomeString()
}

f = 1

while IsKeyLockOn("scrolllock") && f <= Script.Length() do
    Script[f]
    f = f + 1
end

In this script it should call each function one at a time until either condition is not true but this doesn't work and I am not sure what I should be doing.

1

There are 1 best solutions below

0
Silver_Wolf On

This is the answer:

ArbitraryFunction = function(a,b) print(a .. " + " .. b .. " = " .. a+b) end

Script = {
   function() ArbitraryFunction(1,1) end,
   function() ArbitraryFunction(2,3) end,
  }
  
  this = true;

for _, f in pairs(Script) do
  if this == true then
    f()
  end
end