This program has no sleep() in it, yet it's not that fast. It's run on a command computer and it's designed to find all attached blocks to the block underneath the computer and replace them with air.
I know that these computers have the ability to erase the blocks pretty fast, but this is rather slow.
http://pastebin.com/ZpUjb3uP
How can I make this program faster?
Started by CCJJSax, May 27 2016 05:45 PM
5 replies to this topic
#1
Posted 27 May 2016 - 05:45 PM
#2
Posted 27 May 2016 - 05:54 PM
Have you tried looking at this? http://www.computerc...o-optimization/
You may also want to try using http://computercraft...mands.execAsync
You may also want to try using http://computercraft...mands.execAsync
#3
Posted 27 May 2016 - 06:45 PM
commands.getBlockInfo is slow. Try running a few in parallel.
#4
Posted 27 May 2016 - 06:48 PM
KingofGamesYami, on 27 May 2016 - 06:45 PM, said:
commands.getBlockInfo is slow. Try running a few in parallel.
To expand this thread will likely help a lot if you get stuck: http://www.computerc...lockinfo-async/
execAsync will not work due to the fact getBlockInfo can not be used in async.
#5
Posted 27 May 2016 - 10:37 PM
I must not know how to do parallel functions. I looked at the wiki and now it freezes when I put it in. I tried to add a return to the function it calls, but that didn't help and errored saying it was looking for a function and got boolean when I had it return true.
#6
Posted 27 May 2016 - 10:45 PM
A common mistake is to call the function and pass the result to the parallel function. Here's an example of how I would approach this task:
local tCoords = {}
--#add a bunch of coordinates to the tCoords table
local function execCoords()
while #tCoords > 0 do
local x, y, z = (unpack or table.unpack)(table.remove( tCoords, 1 ))
local info = commands.getBlockInfo( x, y, z )
--#do stuff with the info
end
end
local tExecute = {}
for i = 1, 10 do
tExecute[ i ] = execCoords
end
parallel.waitForAll( unpack( tExecute ) )
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











