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

How to stop a loop on a scrolling write

Started by Mindthoth, 07 January 2017 - 06:09 AM
Mindthoth #1
Posted 07 January 2017 - 07:09 AM
Alright so I made two program that I would like to run one after the other and loop it, therefore I made a program called "start"

start program is :


shell.run("mdk")
shell.run("big")



The mdk program is :


local pos = 18

mon = peripheral.wrap("right")
mon.clear()
mon.setBackgroundColor(16384)
mon.setTextColor(32768)

while true do

if pos==-26 then
pos = 18
end

mon.clear()
mon.setCursorPos(pos,1)
mon.setTextScale(5)
mon.write("text")
pos = pos-1

os.sleep(0.15)
end

big program is irrelevant since it doesn't include a loop in it.



Now basically when I call "start" the program keeps the loop of "mdk" (therefore you never see "big") I am trying to find how to make "mdk" loop once and make "start" play "mdk" then "big" and loop both program one after the other.

Thank you so much guys its been a brain tease xD
Bomb Bloke #2
Posted 07 January 2017 - 08:03 AM
One way is to use the parallel API:

parallel.waitForAny(
  function()
    shell.run("mdk")
  end,

  function()
    shell.run("big")
  end
)

If you're on an advanced computer you can alternatively have multishell open one script in a separate tab:

shell.run("bg mdk")
shell.run("big")
Mindthoth #3
Posted 07 January 2017 - 11:20 PM
Thanks for the relpy sadly tho I tried both.

The first code the program doesn't have to time to finish until it jumps to the next one while the second doesn't work at all…. Iam using the advanced computer.
Bomb Bloke #4
Posted 07 January 2017 - 11:40 PM
I can't really comment on how your second script will behave without seeing it.
Mindthoth #5
Posted 08 January 2017 - 12:11 AM
got it to work I just added the shell.run("big") inside of the "mdk" program after "then"