Jump to content




How can I make this program faster?


  • You cannot reply to this topic
5 replies to this topic

#1 CCJJSax

  • Members
  • 262 posts

Posted 27 May 2016 - 05:45 PM

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

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 27 May 2016 - 06:45 PM

commands.getBlockInfo is slow. Try running a few in parallel.

#4 valithor

  • Members
  • 1,053 posts

Posted 27 May 2016 - 06:48 PM

View PostKingofGamesYami, 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 CCJJSax

  • Members
  • 262 posts

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 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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