- Home /
- Moderators /
Code sample misses using directives and class name
I was wondering why users did not format their code blocks right and just came across the same issue. Maybe someone can explain it to me or fix it, I don't know how I made it happen, but it's a little annoying because It's happening to users all the time. It always looks like this using UnityEngine; using System.Collections; using UnityEngine.UI; public class Dotafter3 : MonoBehaviour { Text text;
// Use this for initialization
void Start () {
text = GetComponent<Text> ();
...
Would it be interesting to file a request to the Unity ad$$anonymous$$s for a plugin that scans new paragraphs for "using UnityEngine;" and indents the "whole paragraph including the next indented text"?
This is a site about Unity source code after all and this particular problem case could be automated..
Just saying..
Probably not. People should be posting small, relevant code sections -- ideally from the test code they made to try to isolate the issue. Almost every Q with a using line doesn't belong here. At best, in the Help Room as an "I'm completely lost" Q. In those cases, the messed-up paragraph helps readers see that.
It's also difficult to get changes to the code running the site -- there are several technical fixes which have been on the to-do list for some time.
Yea, you are right.
Although I dream of a feature where you still can post the whole file and then mark a specifc part (or multiple parts) to be shown as "this is relevant". When the reader whishes, he still can expand the code to see more context.
Or at least specify the starting line number of a code snippet to make it match error lines. I am sometimes tempted to just dump whole files to not have to adjust stack trace line numbers or do some cumbersome description "this points to the third line, no wait the fifth and then I removed two lines so the next error is the seventh line blabla.."
Answer by Dave-Carlile · Jan 24, 2016 at 04:19 PM
The code has to be indented 4 spaces to get formatted. You can do this easily by first making sure the first line of code starts on its own line, then select all of the code and press the 101010 button which will do the indentation for you.
The reason you see some code partially formatted is that some of it ends up indented 4 spaces because of the natural indentation that's part of the code.
I was using the pop-up for the code formatting, which means the 4 spaces are not added automatically I guess. Thanks for the explanation.
Answer by Owen-Reynolds · Jan 24, 2016 at 04:38 PM
I think it's someone who pasted their entire file with no attempt at formatting.
4 or more spaces at the start of a line will format it as code. So for the first pasted line indented that far, code-formatting accidentally kicks in. I've never looked, but I suppose the final close-curly brace might also be plain-text.
I also always figured that someone pasting an entire script is just overwhelmed in general. The answer to most of those Q's is something completely unrelated -- like putting the script on the player.
Answer by meat5000 · Feb 10, 2016 at 07:01 PM
People break their formatting when they do it the 'correct way'. This is pressing the code button and dumping your code in it.
Its Broken.
Do it the other way. Highlight and then press the code button.