Jump to content




Help sleep and while true do


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

#1 Kadecamz

  • New Members
  • 113 posts

Posted 11 October 2012 - 08:43 PM

All you need to go is in the code.

allowed = false
term.clear()
term.setCursorPos(1,1)
print("PC"..os.getComputerID().."/ROM/ENTRY")
print("DENIED; ENTER ACCESS CODE")
rs.setOutput("top",false)
rs.setOutput("bottom",false)
rs.setOutput("left",false)
rs.setOutput("right",false)
rs.setOutput("front",false)
rs.setOutput("back",false)
sleep(0)
term.setCursorPos(34,1)
print(os.time())
term.setCursorPos(17,10)
write("USERNAME: ")
term.setCursorPos(34,20)
if allowed = false then
print("ACCESS STATE: FALSE")
if allowed = true then -- Problem is here, getting "bios:328: [string "startup"]:18: then expected
print("ACCESS STATE: TRUE")
end


Ignore above.

Now this isn't really a problem but its been wasting about 30 minutes of my time
I need a grid to show where the Y and Z cords are for term.setCursorPos(?,?)


Now I need to know why sleep does not work in while true do functions




while true do
print("hi")
sleep(3) -- It always is skipped in while true do.
end

Please tell me how to fix.

#2 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 11 October 2012 - 08:45 PM

if allowed = true then
and
if allowed = false then
Is wrong.

if allowed == true then
if allowed == false then

= Sets a variable and == checks it

#3 Kadecamz

  • New Members
  • 113 posts

Posted 11 October 2012 - 08:47 PM

Oh, i always make that mistake. ;p
thanks

#4 Kadecamz

  • New Members
  • 113 posts

Posted 11 October 2012 - 09:02 PM

Now this isn't really a problem but its been wasting about 30 minutes of my time
I need a grid to show where the Y and Z cords are for term.setCursorPos(?,?)

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 11 October 2012 - 09:16 PM

View PostKadecamz, on 11 October 2012 - 09:02 PM, said:

Now this isn't really a problem but its been wasting about 30 minutes of my time
I need a grid to show where the Y and Z cords are for term.setCursorPos(?,?)

1,1 is in the top left. 1,2 is right below it.

#6 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 11 October 2012 - 09:19 PM

It depends on the size of your screen. The X coord i across the top and Y is up and down.

If you do:
local x,y = term.getSize()
it will capture the size of your screen.
You can use the above for a lot of other things.

Mine is 51 x 19 so
1,2,3,4,5,6.....51
2
3
4
5
.
.
.
19


#7 Kadecamz

  • New Members
  • 113 posts

Posted 11 October 2012 - 09:48 PM

TY.
Now I have a problem, when I do while true do, sleeps do not function correctly. (they get skipped)

#8 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 12 October 2012 - 01:03 AM

Can you post updated code?

#9 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 12 October 2012 - 01:12 PM

Sleep() does work in while true do functions. There must be something causing it to not sleep in your code. Is that the only code you have in your program?

#10 ChaddJackson12

  • Members
  • 264 posts

Posted 13 October 2012 - 12:37 AM

I haven't heard of sleep(). But that's just me, maybe. Try using "os.sleep()" instead.

#11 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 13 October 2012 - 12:47 AM

View PostChaddJackson12, on 13 October 2012 - 12:37 AM, said:

I haven't heard of sleep(). But that's just me, maybe. Try using "os.sleep()" instead.

have you been sleeping?? lol sorry bad pun.. sleep() is valid and works great. I've never had to use os.sleep()

#12 ChaddJackson12

  • Members
  • 264 posts

Posted 13 October 2012 - 01:53 AM

View Postluanub, on 13 October 2012 - 12:47 AM, said:

View PostChaddJackson12, on 13 October 2012 - 12:37 AM, said:

I haven't heard of sleep(). But that's just me, maybe. Try using "os.sleep()" instead.

have you been sleeping?? lol sorry bad pun.. sleep() is valid and works great. I've never had to use os.sleep()
Lol, yes, and I wouldn't know about sleep() because I really haven't learned default lua APIs, only ComputerCraft APIs. :)/>

#13 Exerro

  • Members
  • 801 posts

Posted 13 October 2012 - 10:10 AM

try in a different program the code you had
while true do
sleep(3)
print(something)
end
if that doesnt work then you have probably installed computercraft incorrectly





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users