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

How to print a "\"

Started by Techman749, 29 August 2014 - 11:22 AM
Techman749 #1
Posted 29 August 2014 - 01:22 PM
Hello, ComputerCraft Community!

I was trying to create a pinwheel in one of my programs and for some reason the syntax highlighter does not pick up on a [print("\")]. Am I doing something wrong? Here is the code I have for the pinwheel:


term.setCursorPos(1,1)
print("|")
sleep(0.5)
term.setCursorPos(1,1)
print("/")
sleep(0.5)
term.setCursorPos(1,1)
print("-")
sleep(0.5)
term.setCursorPos(1,1)
print("\")
sleep(0.5)
term.setCursorPos(1,1)
print("|")

Any suggestions are accepted! Thanks!
KingofGamesYami #2
Posted 29 August 2014 - 01:23 PM

print( "\\" )
Techman749 #3
Posted 29 August 2014 - 01:25 PM
Thanks!
TheOddByte #4
Posted 29 August 2014 - 06:42 PM
If you want to get a better understanding of it: http://www.lua.org/pil/2.4.html
Cranium #5
Posted 29 August 2014 - 07:34 PM
Since \ is an escape character, in order to actually print it, you need to escape first, then use the slash again.
Hence print("\\")
Anavrins #6
Posted 29 August 2014 - 09:36 PM
As people stated, you need to use the escape character \ if you want to include \ " ' [ ] in strings.
However, if I can suggest, you can save some lines of code by doing this instead.

local pwheel = {"|", "/", "-", "\\"} ## You can add as many frame as you want here without changing the rest of the code
local i = 0
while true do ## You can also use a for loop
  i = (i+1) % #pwheel
  term.setCursorPos(1,1)
  term.write(pwheel[i+1])
  os.sleep(0.5)
end
Edited on 29 August 2014 - 07:37 PM