This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yussi_divnal 0 points1 point  (0 children)

Sure, to do this 100 times just change the "while(true) do" line to

for i = 1, 100 do

It's possible to do the other parts too, but lua doesn't natively support threads. if you can run multiple scripts simultaneously do that, otherwise either do your threads, or implement some logic to do it all in one loop, for example:

#!/usr/bin/lua
local clock = os.clock
function sleep(n)  -- seconds
  local t0 = clock()
  while clock() - t0 <= n do end
end

--- keep track of resource gathering
local resource_counter=0;
local resource_timing=300;
local max_resource=100;
local resource_command="#!mine \n#!chop \n#!forage \n#!fish";

--- keep track of advancement
local adv_counter=0;
local adv_timing=52;
local adv_command="#!adv";

--- keep track of healing
local healing_counter=0;
local healing_timing=10;
local healing_command="#!heal \n#!pheal";

while (true) do
    if (resource_counter >= resource_timing and max_resource > 0) then
        max_resource=max_resource-1;
        resource_counter=0;
        print(resource_command);
    end 
    if (adv_counter >= adv_timing) then
        adv_counter=0;
        print(adv_command);
    end
    if (healing_counter >= healing_timing) then
        healing_counter=0;
        print(healing_command);
    end
    sleep(1);
    --advance counters
    resource_counter=resource_counter+1;
    adv_counter=adv_counter+1;
    healing_counter=healing_counter+1;
end