AddMessage only works in scripts associated with tools in ArcToolbox. That error message means that the script you are using isn't associated with a tool. If you are running a script outside of a tool in ArcToolbox, then you have to use the print statement. If I want to have messages appear both in Arctoolbox's output dialog and when I run a script stand alone, then I do the following
msg = "my message here"
msg2 = "another message"
print msg, "\n", msg2 ( or print('{}\n {}'.format(msg,msg2)) using the newer print statement"
arcpy.AddMessage(msg + "\n" + msg2)
so you will have to clarify where you are running this and include your script portion