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

not sleeping the amount of time.. [lua programming]

Started by Goof, 08 January 2013 - 08:59 AM
Goof #1
Posted 08 January 2013 - 09:59 AM
Hi.

my OS is kinda killing my feets;
it should wait for 2 seconds to continue, but somehow it only shows a function 1/4 of a second, which i dont know why…
( this code is NOT copied. and it will never get out to the forum as official.. it will only be mine, for my games. )

i've written in the start of the program, which line the certain area about the fail, is. ( i've added some quick explainations )
but if anyone could tell me why it doesnt work then it will be really appreciated.
(NOTE: i want so right now, it prints ("LOL") for 2 seconds, so i can see if the problem is solved, and then i will continue coding for myself. )

EDIT:: here is the code.. i was so stupid to not add the code :o/>
:–// :wacko:/> :blink:/> :huh:/>
http://pastebin.com/9NrUGnWb



(eat a hotdog :D/>) ( i dont know why i just said that xD )

Thanks in advance
Edited on 08 January 2013 - 09:01 AM
KaoS #2
Posted 08 January 2013 - 10:36 AM
on line 218 you set loop to false, the moment you do that the next os.pullEvent() will terminate everything because on line 321, 327 and 338 you have


while loop do
  parallel.waitForAny(funcs)
  sleep(0)
end

if you want it to continue use


while true do
  if loop then
	parallel.waitForAny(funcs)
	sleep(0)
  end
end

ALSO

why not store all of those things (run, tRun, obj, sBor, loop and sIcon1) in a table. then you can use a for loop to set them all to false rather than typing it all out

when you manually set all of the colours on line 17 you could just say

for k,v in pairs(colors) do if type(v)==number then rawset(_G,k,v) end end
and it will automatically all all of the colours to the global table making sure you don't leave any out

on lines 27-54 you make many short-hand versions of the normal functions but you do it the long way:

function tP(x,y)
  term.setCursorPos(x,y)
end
could just be

tP=term.setCursorPos

EDIT: even if you changed your loops setting loop to false will pause everything indefinitely… don't set it to false
Edited on 08 January 2013 - 09:40 AM
Goof #3
Posted 08 January 2013 - 10:51 AM
OKay, i will try that…

thanks

edit: it worked now.. Your help is really appreciated… Thank you!
KaoS #4
Posted 08 January 2013 - 06:26 PM
Excellent :)/> oh and one other thing, when running coroutines if any of them write anything to the screen or change the cursor position make them set the position back to default to avoid confusion so for example in the sBorder() function use


function sBorder1()
  while sBor do
    local sMessage = "MikkOS - By Mikk809h"
    local pos={term.getCursorPos()}
    tP(1,1)
    tB(black)
    tT(white)
    tW(sMessage)
    for i = 1, 21 do
	  tCP(i, 1)
    end
    tP(unnpack(pos))
    sleep(0) --move this to the end so you do not os.pullEvent() in the middle of writing to the screen, it should all happen in one instant
  end
end

that way it immediately sets the position back and would not even interrupt something like textutils.slowWrite(). this should also be implemented in the sTime() function
Goof #5
Posted 08 January 2013 - 07:35 PM
Yeah. I was already planning that, because there was a weird setup, when right clicking on the border, but that works fine now :D/>