How to post code on the forum - For absolute beginners


  • Module Developer

    How to post code on the forum. For absolute beginners.

    I’m going to walk you through this. Why? Well, someone always helped me when I was new.
    What better way to repay them? By helping others, that’s how.

    At some point . . .

    You’re going to be asked to post some of your code so that it can be looked at by
    the people here on the forum. It helps them to help you.

    Some of the reasons.

    • MagicMirror is telling you to create a config.js file, but you already did.

    • You added a module and now MagicMirror won’t load.

    • One of your modules just says “Loading…” on your mirror, but never does.

    • You get a black, or white, or blank screen on your mirror.

    • You get a syntax error reported in your terminal or console

    The wrong way

    If you just copy and paste your code into a topic on the forum, the result will look
    something like this. Not too easy to look at, right? It loses its formatting.
    0_1498693087832_wrong.JPG

    Worse than that

    If someone copies the code that you posted (the wrong way) there is an anomaly that often occurs. Some characters will be changed when pasted, causing the code to fail, and leaving you wondering why because you might not notice what characters were
    changed. The most common unwanted changes concern quotes ', double quotes "
    and the comma ,. Can you say, “Syntax error?”

    The right way

    • The secret is . . . the “back-tick”.

    • If you enter one back-tick at the beginning of a word or words and one back-tick at the end of a word or words, you get “inline code” for that word or words.
      Try it in a post. It should look like this. Or, it can look like this.

    You’ll like this

    • Now we want to post a portion (or all) of our config.js file (or any code) in the forum so that it can be viewed easily (and properly) by the people trying to help us.

    • You use three back-ticks before the code AND three back-ticks after the code. That is how you “fence” blocks of code. You will love the result!

    Remember that code posted above?

    • Well, this is how it looks when you “fence” it in with three back-ticks, before AND
      after the code. Tell me you don’t like this better? ;)
    {
        module: 'MMM - PrayerTime',
        position: 'top_left',
            config: {
            apiVersion: '1.0',
            lat: 12.089796,
            lon: -56.807734,
            timezone: 'EST',
            method: 5,
            playAdzan: ['fajr', 'dhuhr', 'asr’, 'maghrib', 'isha'],
            notDisplayed: ['midnight', 'sunset'],
            useUpdateInterval: true,
            updateInterval: 86400 * 1000,
            animationSpeed: 2.5 * 1000,
            language: "en",
            showAdzanAlert: true,
            alertTimer: 15000
        }
    },
    

    Is it a big deal?

    • No, it’s not, but for the sake of conformity we should all post code this way. You’ll like it better (because it looks nicer) and the people reading it will like it better (because it looks better) and we’ll all be one happy forum family.

    • And besides, it’s the way we’re supposed to be doing it. Climb aboard!

    So, where is the back-tick key on my keyboard?

    • On U.S. QUERTY keyboards it’s to the left of the 1 key (not the Numeric keys)

    0_1498693191442_querty.JPG

    But I don’t use a U.S. QWERTY keyboard!

    • You’ll have to determine where yours is if you use a different keyboard.

    • This is the internet. Look it up. You want me to do everything for you?

    An even easier way.

    • Why did I put you through all that? I don’t know. I had to learn it that way so that’s how I teach it.

    • Just do this and forget everything I said above! Simply clicking the icon indicated by the red arrow will place the correct back-ticks in the correct place, with a highlighted //your code here showing you where to paste your code.0_1498859951243_33.JPG

    Peace! :)


  • Module Developer

    Great post!!!!!


  • Module Developer

    @cowboysdude

    Just trying to contribute my friend!

    Thanks!



  • Maybe it should be added that when you have problems finding the correct “back tick” character, you can also use the </> button right above the input field to insert a code-formatted block.


  • Module Developer

    @Anhalter42 said in How to post code on the forum. - For absolute beginners.:

    Maybe it should be added that when you have problems finding the correct “back tick” character, you can also use the </> button right above the input field to insert a code-formatted block.

    Ok noted


  • Module Developer

    @Anhalter42 said in How to post code on the forum. - For absolute beginners.:

    when you have problems finding the correct “back tick” character,

    Really?


  • Admin

    Thanks @Mykle1! Pinned the post to the top :)


  • Module Developer

    @paviro said in How to post code on the forum - For absolute beginners:

    Thanks @Mykle1! Pinned the post to the top :)

    That’s fantastic! Thank you, too!


  • Module Developer

    @Anhalter42 said in How to post code on the forum - For absolute beginners:

    you can also use the </> button right above the input field to insert a code-formatted block.

    Added to the tutorial!



  • i love your "absolute beginners" guides, keep them coming!
    

    thanks a lot !


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.