2 posts
Posted 20 December 2015 - 04:14 PM
okay so i wanna build acinema for me and my friends and then i wanted a scrolling text says Welcome to the cinema
but when i made it it says bios:206: [string "welcome"]:16: ')' expected
local pos = 18
mon = peripheral.wrap("left")
mon.clear()
mon.setBackgroundColor(32)
mon.setTextColor(32768)
mon.setTextscale(5)
while true do
if pos==-26 then
pos = 18
end
mon.clear()
mon.setCursorPos(pos.1)
mon.write("Welcome to the cinema")
pos = pos-1
os.sleep(0.15)
end
8543 posts
Posted 20 December 2015 - 07:39 PM
Moved to Ask a Pro.
2679 posts
Location
You will never find me, muhahahahahaha
Posted 20 December 2015 - 07:45 PM
What does this line mean:
mon.setCursorPos(pos.1)
?
You most probably have to change it to:
mon.setCursorPos(pos[1])
if it is a table. But then
pos = pos -1
would not work.
Decide, is it a number or a table?
If it is a number, it should be:
mon.setCursorPos(pos)
1220 posts
Location
Earth orbit
Posted 20 December 2015 - 07:50 PM
Except mon.setCursorPos(pos) won't work - setCursorPos expects 2 numbers; one each for x and y.
@math586j, is it possible that you meant to use a comma instead of a period/dot?
mon.setCursorPos(pos, 1) --# note the comma instead of the period/dot
Making the above change should allow the text to scroll across the screen. You will, however, have left over characters as the last of the text scrolls offscreen - specifically a bunch of "a"s. I would recommend adding a space to the end of your "Welcome to the cinema" string, like so…
"Welcome to the cinema " --# note the extra space after the end of cinema
EDIT: fixed second example
Edited on 20 December 2015 - 08:19 PM
1852 posts
Location
Sweden
Posted 20 December 2015 - 09:15 PM
I've got a suggestion, use a loop inside your infinite loop that basically loops until the text have gone outside the screen
local mon = peripheral.wrap( "left" )
local w, h = mon.getSize() --# Get the size of the monitor
local x, y = 1, 1 --# The default coordinates of the text
local text = "Welcome to the cinema!"
while true do
while x + #text + 1 >= 1 do --# Loop until the x value + the length of the text is smaller than 1
mon.setCursorPos( x, y )
mon.write( " " .. text .. " " )
sleep( .15 )
x = x - 1
end
x = w -- Reset the x value
end
I haven't tested the code, but I believe it should work.Tested the code, it should work as you'd expect it to
And here's some tips for you
- You can use # to get the length of a string/table
- You can use term.getSize to get the width of the screen, you can use it on the monitor object you've declared aswell, like for example mon.getSize.
- You don't need to use os.sleep, sleep is predefined in CC
- You can use colors.black for example for the colors, you don't have to use their value. http://www.computerc...iki/Colors_(API)
- The newer versions of CC has a function called peripheral.find that automatically finds a peripheral: http://www.computerc...Peripheral.find
Now if you have any more questions, then feel free to ask us.
Edit: Fixed a little mistake with the code, and fixed a comment in it aswell
Edit2: Fixed a syntax error, I've gotten too used to C# lately :P/>
Edited on 20 December 2015 - 08:32 PM