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

Loop Problem

Started by Parkerwowxdx, 04 January 2013 - 12:11 PM
Parkerwowxdx #1
Posted 04 January 2013 - 01:11 PM
Hello Im new to lua. This is a quarry filler interface, that I want to repeat till number is forfillied.
But when I run the program it just stays still even when the timer is up


Here is the program :- http://pastebin.com/vNdeCnun


I know the program but I new and I dont want to compares it…. please if you could just help me with the loop Thank you
ChunLing #2
Posted 04 January 2013 - 02:03 PM
If you want the turtle to actually move, you should probably use some of the movement functions from the turtle API.

Also, if you want your loop to function as a timer, you should probably put a sleep() or something in there.
Parkerwowxdx #3
Posted 04 January 2013 - 02:06 PM
I know I need to move the turtle this is just the beggining interface so I know I have everything there.
Is it possiable to change my code to the timer works becuase I have a sleep() in there already?
ChunLing #4
Posted 04 January 2013 - 03:42 PM
Well, the sleep is before the loop, so it only gets executed once. Try this:

 os.sleep( 10 )
repeat
  Loop = Loop + 1
  write(Loop..", ")
  sleep(0.2) -- or however long you want to wait per loop
until Loop == 50
Really, this would be better handled by a for loop:
for i=1,50 do
  write(i..", ")
  sleep(0.2)
end
But only if you are going to keep it as a numerically iterated loop.
Parkerwowxdx #5
Posted 05 January 2013 - 01:23 AM
Okay I done that and for loop, But if you run it in game, the number do not update am i putting the loop in the wroung place because I am getting confused on why the number are not updating.


Heres the new code : - http://pastebin.com/wqs43Cv3
remiX #6
Posted 05 January 2013 - 01:56 AM
It should update, are you waiting at least 10 seconds because it has a sleep(10)
ChunLing #7
Posted 05 January 2013 - 02:27 AM
Yeah, it updates, but only once every ten seconds. That's why I suggested a shorter time, so you could actually see some results while you were still young enough to care.
Parkerwowxdx #8
Posted 05 January 2013 - 02:27 AM
Yeah

I changed it so that it does it 30 times for 5 secs and it does not update… you can see what I mean if you load it in game
Parkerwowxdx #9
Posted 05 January 2013 - 02:39 AM
Okay so the number that count up to 30 works fine…. but I want the numbers that tell me what in what slot to update and they are not.
remiX #10
Posted 05 January 2013 - 02:41 AM
Mine updates.

Are you sure it doesn't? In your code, only one line will update:
write "Time less till Terinated " write(i..", ")

'i' should change to which number of the loop it is on.

Changed the sleep to 5 seconds or something shorter.
Parkerwowxdx #11
Posted 05 January 2013 - 02:46 AM
yeah mine does that but I want the math

term.clear()
term.setCursorPos(1,1)
print "Welcome to Quarry Filler 101"
print " "
write "Slot 1 | Needs <YourBlock> = " print (full - s1)
write "Slot 2 | Needs <YourBlock> = " print (Upper - s2)
write "Slot 11 | Needs <Wood> = " print (full - s11)
write "Slot 12 | Needs <Wood> = " print (full - s12)
write "Slot 13 | Needs <Wood> = " print (full - s13)
write "Slot 14 | Needs <Wood> = " print (full - s14)
write "Slot 15 | Needs <Wood> = " print (full - s15)
write "Slot 16 | Needs <Wood> = " print (Lower - s16)
print " "


I would like this, to do the math to update every 5 seconds. So if the item in the slot changes then the slot Needed number would change to.

If there a way to do that?
remiX #12
Posted 05 January 2013 - 03:01 AM
You said it wasn't updating, but it was. It has always been.

The math isn't updating because the numbers are always the same. Put the variables within the loop so they update too.
Parkerwowxdx #13
Posted 05 January 2013 - 03:05 AM
It working now thank you very much you 2 were a great help :D/>
Parkerwowxdx #14
Posted 05 January 2013 - 03:31 AM
Is there a way to make so all the slot are 0 to then clear the page. and then start the rest of the program ( not yet written ).
But if the timer got to 30 then the program will terminate.

Heres the new code http://pastebin.com/ut6Gy9BW
ChunLing #15
Posted 05 January 2013 - 03:51 AM
Ah, then we want to go back to using the conditional loop, I think a repeat until in this case. Like so:
local Loop = 1
local x = 2
local w = 8
local full = 64
local Lower = 16
local Upper = 48
--startup
repeat
    if Loop > 30 then return false end
    local s1 = turtle.getItemCount(1)
    local s2 = turtle.getItemCount(2)
    local s11 = turtle.getItemCount(11)
    local s12 = turtle.getItemCount(12)
    local s13 = turtle.getItemCount(13)
    local s14 = turtle.getItemCount(14)
    local s15 = turtle.getItemCount(15)
    local s16 = turtle.getItemCount(16)
    term.clear()
    term.setCursorPos(1,1)
    print "Welcome to Quarry Filler 101"
    print " "
    write "Slot 1  | Needs <YourBlock> = " print (full - s1)
    write "Slot 2  | Needs <YourBlock> = " print (Upper - s2)
    write "Slot 11 | Needs <Wood>	  = " print (full - s11)
    write "Slot 12 | Needs <Wood>	  = " print (full - s12)
    write "Slot 13 | Needs <Wood>	  = " print (full - s13)
    write "Slot 14 | Needs <Wood>	  = " print (full - s14)
    write "Slot 15 | Needs <Wood>	  = " print (full - s15)
    write "Slot 16 | Needs <Wood>	  = " print (Lower - s16)  
    print " "
    write "Time less till Terminated " write(i) print ""
    sleep(5)
    Loop = Loop+1
until full <= s1 and Upper <= s2 and full <= s11 and full <= s12 and full <= s13 and full <= s14 and full <= s15 and Lower <= s16
-- rest of program
Now we are repeating the loop until the conditions are all filled (we have lots of conditions, no?), or until we have looped thirty times, in which case we return out of the program.
Parkerwowxdx #16
Posted 05 January 2013 - 04:01 AM
Edit :- Nvm

|
|
V
Parkerwowxdx #17
Posted 05 January 2013 - 04:04 AM
Also when I ran your code their I got bios:156: bad argument: string expected, got nil
Parkerwowxdx #18
Posted 05 January 2013 - 04:50 AM
Do you know why this happends?
Lyqyd #19
Posted 05 January 2013 - 04:51 AM
You obviously know how to use the edit button, so why are you triple posting? Be patient.
Parkerwowxdx #20
Posted 05 January 2013 - 04:54 AM
sorry
ChunLing #21
Posted 05 January 2013 - 05:22 AM
Line number of the error? It's a little puzzling since I didn't touch anything that takes string arguments.
Parkerwowxdx #22
Posted 05 January 2013 - 05:25 AM
The is also a problem…
I do not have Ln 156
ChunLing #23
Posted 05 January 2013 - 05:29 AM
No, that's the line number in Bios that detected the error. There should be another line number, after the program name.
Lyqyd #24
Posted 05 January 2013 - 05:29 AM
I don't see where i is defined, so I would assume that it is the nil that write() is complaining about.
ChunLing #25
Posted 05 January 2013 - 05:32 AM
Whoops, didn't touch that when I should have. Yeah, the i from the for loop should be replaced with Loop :o/>
Parkerwowxdx #26
Posted 05 January 2013 - 05:34 AM

-- This is what I see on my screen
Slot 1  | Needs <YourBlock> = 64
Slot 2  | Needs <YourBlcok> = 48
Slot 11| Need <Wood> = 64
--etc etc
Time less till Terminated bios:156: bad agument: string expected, got nil
--This is all that I get on my screen





Nevermind I fix it I was writeing the post when you posted your fix Thank you very much for your help and have a lovely day