This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
AFakeman's profile picture

Paralleling problems

Started by AFakeman, 10 May 2013 - 11:51 AM
AFakeman #1
Posted 10 May 2013 - 01:51 PM
I have the following code:


CurrentSlot=1
Finished=false
check=function()
repeat
if turtle.getItemCount(CurrentSlot)==0 then
CurrentSlot=CurrentSlot+1
turtle.select(CurrentSlot)
end
sleep(1)
until Finished

return
end
Arg = {...}
side=tonumber(Arg[1])
cube=function()
foo.bar() (not important part)
Finished=true
end
parallel.waitForAll(check(), cube())
And by some reasons, only check function really works. Why?
Kingdaro #2
Posted 10 May 2013 - 02:00 PM
Remove the parentheses.


parallel.waitForAll(check, cube)
AFakeman #3
Posted 10 May 2013 - 02:23 PM
Remove the parentheses.


parallel.waitForAll(check, cube)
Thank You! I have another problem. Where to look for an error, if program called cube outputs the error:
parallel:22:cube:104 attempt to index "?" (a nill value)
PixelToast #4
Posted 10 May 2013 - 03:23 PM
give us the full code
AFakeman #5
Posted 11 May 2013 - 12:26 AM
CurrentSlot=1
turtle.select(CurrentSlot)
Finished=false


check=function()
repeat
sleep(1)
if (turtle.getItemCount(CurrentSlot)==0)and (CurrentSlot<16) then
CurrentSlot=CurrentSlot+1
turtle.select(CurrentSlot)
elseif (turtle.getItemCount(CurrentSlot)==0)and(CurrentSlot==16) then
CurrentSlot=1
turtle.select(CurrentSlot)
end
until Finished
return
end


stahp=function()
while true do
print("To stop, enter STOP")
msg=read()
if msg=="STOP" then
Finished=true
return
else
print("To stop, enter STOP")
end
end
end


Arg = {...}
side=tonumber(Arg[1])
cube=function()
if side<=3 then
print("Length is too big")
else
  for k=1,side,1 do 
turtle.digDown()
j=0
repeat
turtle.down()
j=j+1
until turtle.detectDown()
repeat
turtle.up()
turtle.placeDown()
j=j-1
until j==0
for n=1,side-1,1 do
turtle.dig()
turtle.forward()
   turtle.digDown()
j=0
repeat
turtle.down()
j=j+1
until turtle.detectDown()
repeat
turtle.up()
turtle.placeDown()
j=j-1
until j==0
end
if k%2==1 then
turtle.turnRight()
   turtle.dig()
turtle.forward()
turtle.turnRight()
else
turtle.turnLeft()
   turtle.dig()
turtle.forward()
turtle.turnLeft()
end
end
for s=1,side-1,1 do
turtle.forward()
end
turtle.turnRight()
for s=1,side,1 do
turtle.forward()
end
turtle.turnRight()
for s=1,side-2,1 do
turtle.up()
turtle.placeDown()
for r=1,4,1 do
for l=1,side-1,1 do
turtle.forward()
turtle.placeDown()
end
turtle.turnRight()
end
end
turtle.up()
turtle.placeDown()
for u=1,side,1 do
for t=1,side-1,1 do
turtle.forward()
turtle.placeDown()
end
if u%2==1 then
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turtle.placeDown()
else
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turtle.placeDown()
end
end
end
Finished=true
return
end
parallel.waitForAll(check, cube, stahp)
Lyqyd #6
Posted 11 May 2013 - 02:25 AM
Just above Finished = true, just above the three ends, you have turtle.turtle.placeDown().
AFakeman #7
Posted 11 May 2013 - 02:54 AM
Just above Finished = true, just above the three ends, you have turtle.turtle.placeDown().
Thank you! I thought I've fixed it, but I guess I was editing the wrong file
AFakeman #8
Posted 11 May 2013 - 12:47 PM
Another question. Any way to detect which music disk you inserted? Also, is it possible to keep computer turned on even if chunk unloaded and loaded back?
PixelToast #9
Posted 11 May 2013 - 01:08 PM
you need chunk loaders to prevent them from shutting down, i would recommend immibis chunk loaders or chickenchunks
to detect the disk name use getAudioTitle
see https://github.com/i...er/diskreceiver to see how it automatically generates a list of disks (57 - 74)
the program requires a disk drive to be infront of the turtle