Jump to content




Weird Loop Glitch



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

#1 Lewisk3

  • Members
  • 150 posts

Posted 25 June 2015 - 09:40 PM

rednet.open("back")
term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1,1);
print("Please Insert Disk")
InsertGUI = true;
--]] Draw GUI [[--
function update()
if(fs.isDir("disk"))then
  error("h")
end
end
function menuLoop()
while InsertGUI do
  update()
end
end
menuLoop()

run and screens black then says too long without yelding then prints the screen?

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 June 2015 - 09:51 PM

Moved to Ask a Pro

#3 Lewisk3

  • Members
  • 150 posts

Posted 25 June 2015 - 09:53 PM

im done with cc too many frustrating glitches, im just done cc has changed my life for the worst, goodbye

#4 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 25 June 2015 - 10:01 PM

Quote

too long without yielding

Yield protection is a ComputerCraft-specific issue, due to the nature of the Java side handling of the Lua environment for the computers. This message means that your program has run for ten seconds without yielding, which usually means you have an infinite loop that is constantly running. You can fix this simply by adding a sleep(0), but it's better to determine how often your code actually needs to run and use an os.pullEvent() to wait for the events it needs. For instance, a loop which looks at changes in redstone state could include an os.pullEvent("redstone") to wait for changes in redstone state before iterating through the loop again.
http://www.computerc...king-questions/


View PostRedxone, on 25 June 2015 - 09:53 PM, said:

im done with cc too many frustrating glitches, im just done cc has changed my life for the worst, goodbye
Slow down, are you sure that these "glitches" are not protection features? For example, this issue is caused by the prevention of monopolization of the lua VM.

Edited by Lupus590, 25 June 2015 - 10:05 PM.


#5 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 25 June 2015 - 10:33 PM

I second Lupus590's suggestion - slow down before you give up. Programming in any language can be a persnickety thing...patience is key. Understanding the problem is an important step in figuring out how to correct it; Lupus590 has your back on that. So just slow down a bit and take another whack at it with some input here in Ask A Pro.

My first question to you is, what exactly are you expecting the program to do as it appears in the OP? I can guess based on the code, but I'd like to know what *you* expect from it first.

For future reference I suggest reading through this thread - don't forget the sections labeled 'Posting a Good Question' and 'Getting Help Faster' near the bottom - those really help us help you.

#6 Lewisk3

  • Members
  • 150 posts

Posted 25 June 2015 - 10:50 PM

View PostLupus590, on 25 June 2015 - 10:01 PM, said:

Quote

too long without yielding

Yield protection is a ComputerCraft-specific issue, due to the nature of the Java side handling of the Lua environment for the computers. This message means that your program has run for ten seconds without yielding, which usually means you have an infinite loop that is constantly running. You can fix this simply by adding a sleep(0), but it's better to determine how often your code actually needs to run and use an os.pullEvent() to wait for the events it needs. For instance, a loop which looks at changes in redstone state could include an os.pullEvent("redstone") to wait for changes in redstone state before iterating through the loop again.
http://www.computerc...king-questions/


View PostRedxone, on 25 June 2015 - 09:53 PM, said:

im done with cc too many frustrating glitches, im just done cc has changed my life for the worst, goodbye
Slow down, are you sure that these "glitches" are not protection features? For example, this issue is caused by the prevention of monopolization of the lua VM.

eh, i fixed the issue. frustrating enough to make me rq though been trying to fix for atleast a whole hour. haven't coded in lua in a while so im a little rusty

View PostDog, on 25 June 2015 - 10:33 PM, said:

I second Lupus590's suggestion - slow down before you give up. Programming in any language can be a persnickety thing...patience is key. Understanding the problem is an important step in figuring out how to correct it; Lupus590 has your back on that. So just slow down a bit and take another whack at it with some input here in Ask A Pro.

My first question to you is, what exactly are you expecting the program to do as it appears in the OP? I can guess based on the code, but I'd like to know what *you* expect from it first.

For future reference I suggest reading through this thread - don't forget the sections labeled 'Posting a Good Question' and 'Getting Help Faster' near the bottom - those really help us help you.


code adapted to

rednet.open("back")
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
print("[Disk Registration] - Waiting For Disk..")

function genKey()
ownKey = math.random(1000000,9999999)
end
while true do

local ev, side = os.pullEvent()
if(ev == "disk" or fs.isDir("disk") )then
  
  genKey()
  rednet.send(2, "check")
  rednet.send(2, ownKey)
  sid, cd = rednet.receive(2)
 
  if(cd)then
  
   if(not fs.exists("disk/.regkey"))then
    f = fs.open("disk/.regkey", "w")
    f.writeLine(ownKey)
    f.close()
    rednet.send(2, "Register")
    rednet.send(2, ownKey)
    print("Created Reg Disk!")
   end
 
  elseif(cd == nil)then
  
   print("Connection to server failed!")
   disk.eject("top")
 
  else
   genKey();
  end
 
end

end

basically i was trying to make a keycard - server side system





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users