"Syntax Error At Line 1"

Aaargh… why does this happen when copy/pasting shaders into Unity? There’s no syntax error happening! I know I’m not the only person that this happens to. What’s the workaround?

Are you using an external text editor? I haven’t come across that sort of error when copying and pasting between shaders code (in the external editor).

Richard.

Yeah, internal editor and SubEtha (also tried TextEdit)… I’m not sure what the problem is. I’ve looked for invisible characters that might be gumming up the works too. It’s very strange, it says the syntax error is on the first line, and if I move the “{” to another line then that becomes the line with the error. It’s very strange and only happens with shader files. Other people have had the same problem and it only happens when copy/pasting text into a new shader… not when bringing in a new shader as a file.

Strange… I use Textmate, but I doubt that will make a difference. I’ll keep an eye on it as I am currently mucking around with shaders.

cheers,
Richard.

Did I mention it’s very strange :wink:

Just noticed I used that twice. I guess I’m just flustered a bit. This problem has popped up ever since I started playing around with custom shaders and I just want to know what I’m doing wrong or if it’s a bug.

I can’t reproduce this. Can you send the exact steps that you’re doing (e.g. create new shader; open in editor; paste this; …) and the shader you’re trying to paste via ReportBug.app?

I vaguely recall a similar thing happening with Javascript some time ago - which was fixed, but not 100% sure.

cheers,
Richard.

I get this “strange” thing also. :wink: Seems to happen if you use any editor other than the built-in one. That is also including code IDEs that wouldn’t add funny return or other fun characters.

Unless you type it in the unity editor, or paste it directly there without a “middle-man” you get that error.

-Jeremy

This happens to me too. I have to retype every shader on the wiki I want to use because I can’t paste it in, even in the built in editor or I will get a Syntax error at line 1.

What browser are you pasting from?

Some webbrowsers replace spaces with non-breaking spaces when pasting scripts into text editors.

I am using Camino or Safari, both don’t work.

Yeah, it must be a web browser formatting problem. Along with Safari and Camino, Firefox doesn’t work either. It would be cool if the Wiki had downloadable Zips for shaders instead of copy/paste.

Weird (no wait, strange :wink:) that this doesn’t happen for copy/pasting scripts, just shaders?

[Edit] I noticed that if I move the first “{” of the shader file to another line then that line becomes the syntax error.

Haha, I finally found a workaround! Paste the shader text into Xcode and save as “whatever.shader”. Works like a charm, it must strip out whatever extraneous characters that were screwing this up. Xcode is of course free for everyone using a mac.

won’t pasting into textedit and making it plain text remove non-breaking spaces? still a work around and just an alternate to xcode. i didn’t try and i guess it’s kind of a whatever works!

That method doesn’t work for some reason… I’ve tried a number of text editors and Xcode is the first one I found that works.

ah well just a thought. glad you tried and clarified it doesn’t work! i’m off to bed… later!

The wiki is a community effort so if anyone knows of a decent way to set up the script downloads with MediaWiki please let someone know… posting in the forum should do the trick.

Until then, what I do is click edit on the script section, then copy the relative text… close off without making any changes, then type this into the Terminal:

pbpaste | unexpand -t 4 | pbcopy

What that does is takes what’s in the clip board and change four spaces into one tab… This is optional. A lot of scripts use spaces instead of tabs. (if you see one that doesn’t, please fix it)

Then paste it into whatever text editor.

-Jon

Could you paste the same script into two editors (one working and one non-working) and either attach both to this thread or mail them to me (hlodversson at [that google mail thing]), and I’ll take a look at what that character is. (Then, I could possibly find a way to strip the bad characters on the wiki side.)

Thanks freyr, here’s a paste into Xcode and one into TextEdit. It’s the “VegetationTwoPass” from the Wiki.

Okay… the difference is that textEdit saves the files with Mac line endings (CR, ascii 13) wheras Xcode uses Unix line endings (LF, ascii 10). You should be able to use SubEthaEdit – just make sure it uses Unix line endings.

You can convert the endings using perl on a command line like this:

perl -pi.bak -e 's/\r/\n/g' File_to_convert.shader

PS. I added a change request to the OTEE bug tracking system to let shadrelab support Mac (CR) and Dos (CR+LF) line endings in addition to just Unix (LF). ( Case 2761: Shaderlab should support alternate line endings )