x


How do you format scripts in UnityAnswers?

I pressed the "101 010" button and its says place code here. I cut and paste right where it says "enter code here", but my code is never formatted correctly. Would someone please explain how to format my code in a little more detail? Thanx

more ▼

asked Jul 28 '11 at 11:25 AM

DFiable gravatar image

DFiable
141 43 54 55

I'm wondering, are you guys also experiencing problems with line spacing when copy-pasting from MonoDevelop? For me, and some others, between each line a blank line gets inserted.

Any way to prevent this?

Jul 28 '11 at 12:35 PM Joshua

@Joshua I see random empty lines inserted when pasting from Visual Studio as well...

Jul 28 '11 at 05:01 PM Herman Tulleken

That sounds like newline format mismatch to me. What browser are you guys using? http://en.wikipedia.org/wiki/Newline

Jul 29 '11 at 10:48 AM Statement ♦♦

+1 for asking a question all posters can benefit from. :) (Correctly formatted code == getting yelled at less && receive more help) = true

Jul 29 '11 at 11:20 AM CHPedersen

@Christian H Pedersen :

Unknown identifier :P

Jul 29 '11 at 11:27 AM biohazard
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

I usually just paste some code, select it all, and press the 101 010 button.

So, make sure you have selected your code before pressing 101 010 button.

Actually, I just format it in my editor before sending it out, it's easier imo. Just make sure you got 4 spaces before each line of code. I select all text, press tab to indent them with 4 spaces, then I copy & paste it here.

more ▼

answered Jul 28 '11 at 11:54 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(Upvoted and selected this as the right answer)

Jul 29 '11 at 11:19 AM CHPedersen
(comments are locked)
10|3000 characters needed characters left

As an addition to the other answers here, all the formatting rules apply in the comments space as well as in the Q&A forms, there's just no handy formatting feature for it.

In the case I want to put code into a comment, I either add 4 spaces (if it's a short snippet) or compose the comment in the answer box first, ensure it's formatted correctly, then cut/paste it into the comment field.

The formatting is based on Markdown Syntax and you can use many of the features listed in the syntax reference here.

more ▼

answered Jul 28 '11 at 05:00 PM

Chris D gravatar image

Chris D
2.5k 5 7 25

(comments are locked)
10|3000 characters needed characters left

if you format your code with the 101010-button and work on it afterwards, sometimes that breaks the formating again.

so personally I prefer formating-tags:
< pre> < code>

This is Code
< /code> < /pre>
(you have to remove the space after the ' < ' for them to work)

also note: all other html-tags for formatting (order and unorderd lists, bold, links etc work just as fine)

EDIT: Warning: apparently some browsers display the tags instead of formatting the code :(( booh!

Greetz, Ky.

more ▼

answered Jul 31 '11 at 03:09 AM

SisterKy gravatar image

SisterKy
2.4k 33 41 59

(comments are locked)
10|3000 characters needed characters left

All I do is press that button, copy my code, highlight where is says "enter code here" and then just paste. And I have also noticed that if you don't indent between curly braces it tends to not format correctly.

more ▼

answered Jul 28 '11 at 12:12 PM

dibonaj gravatar image

dibonaj
233 13 17 17

Actually, that's the wrong way (at least in Chrome). It'll only indent the first line of code. Paste the code, select the code, then press the 101 010 button.

Jul 28 '11 at 12:40 PM Statement ♦♦

Good thing I don't use Chrome then. Works every time in Firefox.

Jul 28 '11 at 12:49 PM dibonaj

I should also note that I am insanely picky when it comes to formatting my code inside of MonoDevelop (or anything I may be using to do my coding in). So I don't know if you have "poor" formatting techniques if that'll translate over to how it gets pasted here.

Jul 28 '11 at 12:57 PM dibonaj

Thanx Guys. Well my code is nice and then ends up scrambled. Thanx again guys.

Jul 28 '11 at 04:49 PM DFiable

dibonaj, are you sure about that? I don't mean to go into a crusade or anything but I picked the first answer from you that I could find some code in, and it's wrong. http://answers.unity3d.com/questions/147225/infinitely-repeating-sound-when-minimizing-web-pla.html The first line is indented, the second line is not. It's a flurry of indented and non-indented.

Jul 28 '11 at 05:14 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x141
x69
x8

asked: Jul 28 '11 at 11:25 AM

Seen: 1049 times

Last Updated: Aug 05 '11 at 09:44 PM