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

Weird Loop Conditional Question

Started by BlueZero, 20 June 2016 - 12:29 PM
BlueZero #1
Posted 20 June 2016 - 02:29 PM
Ohi thar!

I've kind of had an idea so I can prevent coding noise and repeatedly typing the same bloody thing over and over, so here's my question with something I found I was doing a lot; can something like this be done:


while text in print() do
  write("Herp.\n")
end
print("Derp.")

Now with my somewhat flunky logic here, I am expecting an outcome to be something like an output like "Herp." being printed before "Derp." is printed 'cause it's looking for the print function to be called. Is there a way to do this? I'm wanting to apply this kind of logic to a sleep function so when printing a lot of text on the screen, it doesn't just simply flash across the screen in 0.5/^8 seconds. Instead of having to write "sleep(0.5)" when I print something out, I could just simply have it as a "make shift" condition applying to the print function. Anyone get what I'm layin' down here or is there another way of doing this?

Tried googling but couldn't get the right search terms if something like this is already out there, so as far as I know nothing seems to be covering this.
Edited on 20 June 2016 - 12:39 PM
Bomb Bloke #2
Posted 20 June 2016 - 04:02 PM
Not entirely sure what you're asking for (I don't see how the while loop comes into it?), but it sounds like you could just do something like this:

local function printSleep(text)
  print(text)
  sleep(0.5)
end

printSleep("Hello")
printSleep("World")

… though it may be that textutils.pagedPrint() covers your needs.
eniallator #3
Posted 20 June 2016 - 08:09 PM
Or you could use something like this:

local tableOfPrintMessages = {"line1","line2","line3"}

for i=1, #tableOfPrintMessages do
  if i > 1 then

    sleep(0.5)
  end -- #This is to make it only sleep when there are multiple values in the tableOfPrintMessages table

  print(tableOfPrintMessages[i]) -- #This prints the current value in the table that i corresponds to
end
BlueZero #4
Posted 21 June 2016 - 01:02 AM
Oh wow, Eniallator nailed it. That's pretty much what I was wanting to do. I think maybe I'll set a bunch of different text to work with within a table and just call upon them like that when I need to. Either that or flush the table every time I get to a new section and apply specific text for each section to call upon?

I don't know, too many ways to do this, lol. Thanks a lot you two. Very much helps.