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

[question][error] - yielding

Started by tesla1889, 01 July 2012 - 07:59 PM
tesla1889 #1
Posted 01 July 2012 - 09:59 PM
is there a way to force a yield? no matter what i do with this code segment, i always end up with a bios:25: too long without yielding


i4 = 0
for i3 = 1,1398 do
for i1 = (i4 + 1),(i4 + 6000) do
  local t1 = bit.tobits(i1)
  while #t1 < 32 do
  table.insert(t1,0)
  end
  s1 = ""
  s2 = ""
  for i2 = 1,32 do
   s1 = s1..t1[i2]
   s2 = s2.."0"
  end
  t1 = {}
  table.insert(t1,s1)
  table.insert(t1,s2)
  table.insert(mem,t1)
end
i4 = i4 + 6000
sleep(0.01)
end
sleep(0.01)
for i1 = (i4 + 1),(i4 + 608) do
local t1 = bit.tobits(i1)
while #t1 < 32 do
table.insert(t1,0)
end
s1 = ""
s2 = ""
for i2 = 1,32 do
  s1 = s1..t1[i2]
  s2 = s2.."0"
end
t1 = {}
table.insert(t1,s1)
table.insert(t1,s2)
table.insert(mem,t1)
end

Edit: solved. it didn't like the 32 bits for some reason, so i changed it to 16 and scaled back the process to 16-bit and it worked.
Lyqyd #2
Posted 01 July 2012 - 10:55 PM
Yeah, somewhere in your ridiculously-many-iterations loops, put a sleep(0) call. Might need to be sleep(0.1), but the first should work.
MysticT #3
Posted 01 July 2012 - 11:04 PM
I don't know what you'r trying to do, but the simplest way would be to use a function like:

local function yield()
  os.queueEvent("fake")
  os.pullEvent("fake")
end
That way, it will yield but won't wait for an event.

EDIT:
lol, didn't even think about using sleep :P/>/>.