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

How do i make a marquee?

Started by CardingiSFun, 06 October 2012 - 09:46 PM
CardingiSFun #1
Posted 06 October 2012 - 11:46 PM
so i was wondering how do i make a marquee cause im on tekkit and me and a friend are making a video but we need to use computer craft monitors and we need to have a marquee. so please can someone show me how?
Kingdaro #2
Posted 07 October 2012 - 12:03 AM
Alright so first, you'll probably want your marquee text.

local text = 'My Marquee Text'

Then, you're going to start a while loop, so that the marquee keeps going.

while true do

For this, we're going to use a for loop, that starts off with drawing the text off-screen, and ends with drawing it off-screen again, but to the right.

This for loop is going to start at the width of the screen, which we'll need to get with term.getSize(). And it's going to end at the right, but completely offscreen, so 0 - the length of your text.

 local width, height = term.getSize()
 for x=width, -#text, -1 do

We clear the screen so that anything drawn previously won't still be shown. Then we simply set our position, and print the text. Sleep, so that the loop doesn't go too fast. After that we're done, so we just end off our loops.

  term.clear()
  term.setCursorPos(x, 1)
  print(text)
  sleep(0.1)
 end
end

Run this on a monitor and you're good.
CardingiSFun #3
Posted 07 October 2012 - 12:13 AM
thats not working for me i get | startup:15: 'for' initial value must be a number |
thats my error
Kingdaro #4
Posted 07 October 2012 - 12:39 AM
The script is only 10 lines long, how are you getting the error on line 15?
CardingiSFun #5
Posted 07 October 2012 - 12:49 AM
o i have a few lines above it
Lyqyd #6
Posted 07 October 2012 - 12:51 AM
Then post the whole script you're using.
CardingiSFun #7
Posted 07 October 2012 - 01:05 AM
http://imgur.com/a/HkRPO theres the pics of the script

o got it to work but now it just spams it in console not on the monitor

and it spams t's first then the text marquee's
Kingdaro #8
Posted 07 October 2012 - 01:28 AM
In that case, you'll want to do mon.setCursorPos and mon.write instead of term.setCursorPos and write. Instead of using term.clear, you would only clear the line your marquee is on.

Here's a revised snippet:


local text = 'My Marquee Text'
while true do
 local width, height = term.getSize()
 for x=width, -#text, -1 do
  mon.clearLine(10)
  mon.setCursorPos(x, 10)
  mon.write(text)
  sleep(0.1)
 end
end