So you can see the spacing required to play any major chord on the strings of the guitar.If you get the spacing right, it will sound right to the ear.This is the science behind it, but you would be much better off to find out for youself, playing by ear.You get collections of notes that sound right that are not major chords,i.e the spacing of the tones and semitones is different.However there is a rule that defines what sort of scale it is, defined by the spacing of its tones and semitones. In a minor chord, say D minor, the tones and semitones will be in a different place to the Major scale, BUT this spacing will be the law for ALL Minor scales.And so on for other types of scales. Very logical, music!.
However go on selecting groups of notes that sound right to the ear, and I sugest to you ,you pick out the D major scale on the 1st (highest) string to introduce yourself to the way scales are constructed, and I suggest ,to start off with ,you learn by ear.As sugested before do it with 3/4 notes at a time , which is the harder part, and follow through with the, easier, next 3/4 notes. Build a scale in this way of 7 notes that sound right to the ear, without worrying what tha scale might be called. It doesnt have to be D major.
E major, for instance would start off on the 2nd and 4th and 5th fret ,of the first string, folowed by a similar tetrachord.
You can check later to see what scale you have chanced upon, that seems right to you ear.By that time you will be playing your own tune!.