BrunoZockt, on 20 August 2018 - 05:25 AM, said:
I don't really understand what you mean, this code works exactly like it's intended to.
As an example, this code won't error out:
if true then
print("hello")
elseif error("goodbye") then
print("argh")
end
... and this snippet won't attempt to evaluate tbl.key if tbl isn't a table (hence avoiding an "attempt to index into something that isn't a table" error):
if type(tbl) == "table" and tbl.key == "pie" then
Evaluation stops as soon as the final result is known - the Lua VM doesn't bother to parse the rest of your conditional statement if it doesn't need to. I mentioned it because
without access to your full source, I had no way to know whether Fuel() could return prior to refuelling the turtle. If it
could, then that could in turn prevent dig() from ever being called, as it's contingent on a certain "elseif" being reached within your code.
BrunoZockt, on 20 August 2018 - 05:25 AM, said:
Insert() inserts a chunk of code into the toDoList. It uses index 2 and increasing because the inserted code needs to be called next. Index 1 however is the chunk of code that called insert() in the first place and needs to be removed after successfull execution. The index is set back to 2 now, so that insert() -if called- doesn't push away the chunk at index 1 which again needs to be removed.
Say you're calling chunk 1 from slot 1. It inserts chunk 2 into slot 2, and then chunk 3 into slot 3. "index" has been increased to 4 by this point, by the insert() function.
Chunk 1 returns and is removed from the list, chunk 2 goes into slot 1, chunk 3 goes into slot 2, index gets "set to 2" (as opposed to "reduced by 1").
Chunk 2 starts execution and inserts chunk 4 into slot 2, bumping chunk 3 back into slot 3 again...
The result isn't the first-in-first-out system I would expect.
BrunoZockt, on 20 August 2018 - 05:25 AM, said:
I really don't recommend looking into it, it's horribly messy and I've provided everything that's related but I guess I can't stop you:
You're localising "insert" on line 99. If you assigned a function pointer to it in the global scope before doing that you'd technically have two different variables, but since you're doing it after, your function declaration is just overwriting the table pointer stored within the local variable.
Best to use separate names there.
Edited by Bomb Bloke, 20 August 2018 - 02:30 PM.