Make postings easier to read with [code] tags

Posted by Nick Gammon on Wed 19 Aug 2009 09:25 PM — 1 posts, 11,541 views.

Australia Forum Administrator #0
If you are posting script (or C) code, or triggers, aliases or timers copied from MUSHclient, it is much more readable if you use the [code] ... [/code] tags around it. For example, without the tags:



function mytrigger (name, line, wildcards)
if wildcards [1] == "sword" then
Send "wield axe"
else
if wildcards [2] == "now" then
Send "flee"
else
Send "kick"
end -- if
end -- if
end -- function



The above example is not monospaced, and is not indented, so it is hard to read. (This also applies to MUD output, which is often monospaced).

It looks better like this:


function mytrigger (name, line, wildcards)
  if wildcards [1] == "sword" then
    Send "wield axe"
  else
    if wildcards [2] == "now" then
      Send "flee"
    else
      Send "kick"    
    end -- if
  end -- if
end -- function


To achieve the improved look, simply put [code] at the start of the code snippet, and [/code] at the end. If you are editing an existing post, make sure that "Forum codes" (under the post) is checked.

However there is a small problem - if your post has square brackets or backslashes in it, the forum may misinterpret them as forum tags. For example, if your script had [i] in it, that would make everything after it appear in italics.

You need to ensure that square brackets inside your post are not misinterpreted by "escaping" them.

  • To do this, copy the code to the clipboard
  • Then use MUSHclient's Edit menu -> "Convert Clipboard Forum Codes" (Shift+Ctrl+Alt+Q)
  • Paste the converted code into the forum posting (between the [code] and [/code] tags).


Now your code will look monospaced and much easier to read.

In this example, when looking at the posting whilst editing it in the forum, you would see this:


[code]
function mytrigger (name, line, wildcards)
  if wildcards \[1\] == "sword" then
    Send "wield axe"
  else
    if wildcards \[2\] == "now" then
      Send "flee"
    else
      Send "kick"    
    end -- if
  end -- if
end -- function
[/code]