Jump to content




Too Long Without Yielding


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

#1 AlwayzPatrick

  • New Members
  • 1 posts

Posted 11 April 2015 - 08:44 AM

Hi i have build a computercraft program and i used it for Greg's SG
but if i use it 5 seconds later it says this: Too Long Without Yielding
what must i do

-CODE-

SG = peripheral.find("stargate")
mon = peripheral.wrap("top")

--SG + MON--
St, C = SG.stargateState()
LA = SG.localAddress()
RA = SG.remoteAddress()

function INF()
while true do
mon.setBackgroundColor(colors.white)
mon.setTextColor(colors.red)
mon.setCursorPos(1,1)
mon.write("The Stargate = "..St)
mon.setCursorPos(1,2)
mon.write("The Local Addres = "..LA)
mon.setCursorPos(1,3)
mon.write("Locked Chevrons = "..C)
mon.setCursorPos(1,4)
mon.write("Dialling To = "..RA)
end
end
INF()

#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 11 April 2015 - 05:13 PM

add sleep(0) in the while true do loop. ;)

#3 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 11 April 2015 - 05:20 PM

The way you've structured your code, I have a feeling that it isn't going to work the way you want it to.

Currently, you set your variables, then you just print them to the screen over and over again, but you never set them to anything else since they are outside the loop - some of them (like remoteAddress) will change over time so you want to update them regularly. Also, you should localize your variables (and, by extension, your functions) unless you need or want them to be accessible to other programs on the same computer - locals are also slightly faster which is always good. The following will ensure you get 'up to date' information in your loop.
local SG = peripheral.find("stargate")
local mon = peripheral.wrap("top")
local LA = SG.localAddress()

local function INF()
  while true do
    local St, C = SG.stargateState()
    mon.setBackgroundColor(colors.white)
    mon.setTextColor(colors.red)
    mon.setCursorPos(1,1)
    mon.write("The Stargate = "..St)
    mon.setCursorPos(1,2)
    mon.write("The Local Addres = "..LA)
    mon.setCursorPos(1,3)
    mon.write("Locked Chevrons = "..C)
    mon.setCursorPos(1,4)
    mon.write("Dialling To = "..SG.remoteAddress())
    sleep(0)
  end
end

INF()

Edited by Dog, 11 April 2015 - 05:29 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users